From f6df19b1f7c26794dec75eb49686a19ecf22e504 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Sun, 18 Nov 2012 12:01:39 +0000 Subject: [PATCH] Some speed optimization. --- lib/clean.js | 7 ++++--- test/unit-test.js | 15 +++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/clean.js b/lib/clean.js index a8e43728..7a3b1098 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -24,6 +24,7 @@ var CleanCSS = { else data = data.replace.apply(data, arguments); }; + var lineBreak = process.platform == 'win32' ? '\r\n' : '\n'; options = options || {}; @@ -81,8 +82,8 @@ var CleanCSS = { replace(/;[ ]?;+/g, ';'); // multiple line breaks to one - replace(/ (\r\n|\n)/g, '$1'); - replace(/(\r\n|\n)+/g, '$1'); + replace(/ (?:\r\n|\n)/g, lineBreak); + replace(/(?:\r\n|\n)+/g, lineBreak); // remove spaces around selectors replace(/ ([+~>]) /g, '$1'); @@ -149,7 +150,7 @@ var CleanCSS = { // zero + unit to zero replace(/(\s|:|,)0(px|em|ex|cm|mm|in|pt|pc|%)/g, '$1' + '0'); - replace(/rect\(0(px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0'); + replace(/rect\(0(?:px|em|ex|cm|mm|in|pt|pc|%)/g, 'rect(0'); // none to 0 replace(/(border|border-top|border-right|border-bottom|border-left|outline):none/g, '$1:0'); diff --git a/test/unit-test.js b/test/unit-test.js index ae8e0cf5..068f3202 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -2,6 +2,7 @@ var vows = require('vows'), assert = require('assert'), cleanCSS = require('../index'); +var lineBreak = process.platform == 'win32' ? '\r\n' : '\n'; var cssContext = function(groups, options) { var context = {}; var clean = function(cleanedCSS) { @@ -117,15 +118,21 @@ vows.describe('clean-units').addBatch({ ] }), 'line breaks': cssContext({ - 'line breaks': 'div\na\r\n{width:500px}', - 'line breaks #2': 'div\na\r\n,p{width:500px}', + 'line breaks': [ + 'div\na\r\n{width:500px}', + 'div' + lineBreak + 'a' + lineBreak + '{width:500px}' + ], + 'line breaks #2': [ + 'div\na\r\n,p{width:500px}', + 'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}' + ], 'multiple line breaks #2': [ 'div \r\n\r\na\r\n,p{width:500px}', - 'div\r\na\r\n,p{width:500px}' + 'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}' ], 'line breaks with whitespace lines': [ 'div \n \t\n \na\r\n, p { width:500px }', - 'div\na\r\n,p{width:500px}' + 'div' + lineBreak + 'a' + lineBreak + ',p{width:500px}' ] }, { keepBreaks: true }), 'selectors': cssContext({ -- 2.34.1