Adds faster Token#detokenize.
authorJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 8 Jun 2014 19:51:01 +0000 (20:51 +0100)
committerJakub Pawlowicz <jakub@goalsmashers.com>
Sun, 8 Jun 2014 20:34:35 +0000 (21:34 +0100)
lib/properties/token.js

index bad10aa..209c545 100644 (file)
@@ -110,6 +110,8 @@ module.exports = (function() {
         tokens = [tokens];
       }
 
+      var result = '';
+
       // This step takes care of putting together the components of shorthands
       // NOTE: this is necessary to do for every shorthand, otherwise we couldn't remove their default values
       for (var i = 0; i < tokens.length; i++) {
@@ -119,28 +121,22 @@ module.exports = (function() {
           Array.prototype.splice.apply(tokens, [i, 1].concat(news));
           t.isDirty = false;
           i--;
+          continue;
         }
-      }
 
-      // And now, simply map every token into its string representation and concat them with a semicolon
-      var str = tokens.map(function(token) {
-        var result = '';
+        if (t.prop)
+          result += t.prop + ':';
 
-        // NOTE: malformed tokens will not have a 'prop' property
-        if (token.prop) {
-          result += token.prop + ':';
-        }
-        if (token.value) {
-          result += token.value;
-        }
-        if (token.isImportant) {
+        if (t.value)
+          result += t.value;
+
+        if (t.isImportant)
           result += important;
-        }
 
-        return result;
-      }).join(';');
+        result += ';';
+      }
 
-      return str;
+      return result.substr(0, result.length - 1);
     };
 
     // Gets the final (detokenized) length of the given tokens