Speeds up restructuring.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 22 Feb 2015 11:36:38 +0000 (11:36 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 25 Feb 2015 22:04:54 +0000 (22:04 +0000)
We don't need to do a full selector cleanup, just remove repetitions
and remap.

lib/selectors/optimizers/advanced.js
lib/selectors/optimizers/clean-up.js

index c0f7417..8fe33c3 100644 (file)
@@ -398,7 +398,6 @@ AdvancedOptimizer.prototype.mergeNonAdjacentByBody = function (tokens) {
 AdvancedOptimizer.prototype.restructure = function (tokens) {
   var movableTokens = {};
   var movedProperties = [];
-  var adjacentSpace = this.options.compatibility.selectors.adjacentSpace;
   var self = this;
 
   function tokensToMerge(sourceTokens) {
@@ -438,7 +437,7 @@ AdvancedOptimizer.prototype.restructure = function (tokens) {
       beforeSize += selectorLength;
     }
 
-    allSelectors = CleanUp.selectors(allSelectors, false, adjacentSpace);
+    allSelectors = CleanUp.selectorDuplicates(allSelectors);
     afterSize += allSelectors.list.join(',').length + valueSize;
 
     if (afterSize < beforeSize)
index 5c2555e..878f4b9 100644 (file)
@@ -47,6 +47,25 @@ var CleanUp = {
     };
   },
 
+  selectorDuplicates: function (selectors) {
+    var plain = [];
+    var tokenized = [];
+
+    for (var i = 0, l = selectors.length; i < l; i++) {
+      var selector = selectors[i];
+
+      if (plain.indexOf(selector.value) == -1) {
+        plain.push(selector.value);
+        tokenized.push(selector);
+      }
+    }
+
+    return {
+      list: plain.sort(),
+      tokenized: tokenized.sort(selectorSorter)
+    };
+  },
+
   block: function (block) {
     return block
       .replace(/\s+/g, ' ')