Speeds up simple reduction by using for loop not map.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 5 Oct 2014 14:43:44 +0000 (15:43 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 10 Oct 2014 20:22:45 +0000 (21:22 +0100)
lib/selectors/optimizers/simple.js
test/selectors/optimizers/simple-test.js

index a112966..fda627e 100644 (file)
@@ -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) {
index e5d167a..0ab07a9 100644 (file)
@@ -267,11 +267,11 @@ vows.describe(SimpleOptimizer)
     propertyContext('ie hacks', {
       'underscore': [
         'a{_width:100px}',
-        ['']
+        []
       ],
       'star': [
         'a{*width:100px}',
-        ['']
+        []
       ]
     })
   )