Tweaks performance of multiproperty restructuring.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 19 Apr 2015 13:42:17 +0000 (14:42 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 19 Apr 2015 13:42:17 +0000 (14:42 +0100)
We compare property names first then head to comparing a body which
adds a stringify step.

lib/selectors/optimizers/advanced.js

index 3963d79..f0981ba 100644 (file)
@@ -472,13 +472,15 @@ AdvancedOptimizer.prototype.restructure = function (tokens) {
       var mergeableToken = mergeableTokens[i];
 
       for (j = mergeableToken[2].length - 1; j >= 0; j--) {
+        var mergeableProperty = mergeableToken[2][j];
 
         for (k = 0, m = properties.length; k < m; k++) {
           var property = properties[k];
 
-          var mergeablePropertyKey = stringifyBody([mergeableToken[2][j]]);
-          var propertyKey = property[4];
-          if (mergeablePropertyKey === propertyKey) {
+          var mergeablePropertyName = mergeableProperty[0][0];
+          var propertyName = property[0];
+          var propertyBody = property[4];
+          if (mergeablePropertyName == propertyName && stringifyBody([mergeableProperty]) == propertyBody) {
             mergeableToken[2].splice(j, 1);
             break;
           }