From: Jakub Pawlowicz Date: Sun, 8 Jun 2014 19:51:01 +0000 (+0100) Subject: Adds faster Token#detokenize. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8fbdf946550c4433851f2d3474dfb2e6056ce8af;p=clean-css.git Adds faster Token#detokenize. --- diff --git a/lib/properties/token.js b/lib/properties/token.js index bad10aa7..209c5457 100644 --- a/lib/properties/token.js +++ b/lib/properties/token.js @@ -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