From db29877b6b7b58a1a25bb587f548ca729a1928c0 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 5 Oct 2014 15:43:44 +0100 Subject: [PATCH] Speeds up simple reduction by using for loop not map. --- lib/selectors/optimizers/simple.js | 13 +++++++++---- test/selectors/optimizers/simple-test.js | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/selectors/optimizers/simple.js b/lib/selectors/optimizers/simple.js index a112966e..fda627ec 100644 --- a/lib/selectors/optimizers/simple.js +++ b/lib/selectors/optimizers/simple.js @@ -169,14 +169,17 @@ function colorMininifier(property, value, compatibility) { } function reduce(body, options) { - return body.map(function (token) { + var reduced = []; + + for (var i = 0, l = body.length; i < l; i++) { + var token = body[i]; var firstColon = token.indexOf(':'); var property = token.substring(0, firstColon); var value = token.substring(firstColon + 1); var important = false; if (!options.compatibility && (property[0] == '_' || property[0] == '*')) - return ''; + continue; if (value.indexOf('!important') > 0 || value.indexOf('! important') > 0) { value = value.substring(0, value.indexOf('!')).trim(); @@ -195,8 +198,10 @@ function reduce(body, options) { value = multipleZerosMinifier(property, value); value = colorMininifier(property, value, options.compatibility); - return property + ':' + value + (important ? '!important' : ''); - }); + reduced.push(property + ':' + value + (important ? '!important' : '')); + } + + return reduced; } SimpleOptimizer.prototype.optimize = function(tokens) { diff --git a/test/selectors/optimizers/simple-test.js b/test/selectors/optimizers/simple-test.js index e5d167af..0ab07a94 100644 --- a/test/selectors/optimizers/simple-test.js +++ b/test/selectors/optimizers/simple-test.js @@ -267,11 +267,11 @@ vows.describe(SimpleOptimizer) propertyContext('ie hacks', { 'underscore': [ 'a{_width:100px}', - [''] + [] ], 'star': [ 'a{*width:100px}', - [''] + [] ] }) ) -- 2.34.1