Speeds up merging by body advanced optimization.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 Jan 2016 15:15:18 +0000 (15:15 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 3 Jan 2016 15:30:38 +0000 (15:30 +0000)
Testing #715 revealed `mergeNonAdjacentByBody` spends lots of time
optimizing selectors with empty body, which, at the end, will be
removed.

History.md
lib/selectors/merge-non-adjacent-by-body.js

index 882a53c..28fcfe6 100644 (file)
@@ -6,6 +6,7 @@
 [3.4.9 / 2016-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.8...3.4)
 ==================
 
+* Sped up merging by body advanced optimization.
 * Fixed issue [#693](https://github.com/jakubpawlowicz/clean-css/issues/693) - restructuring edge case.
 * Fixed issue [#711](https://github.com/jakubpawlowicz/clean-css/issues/711) - border fuzzy matching.
 * Fixed issue [#714](https://github.com/jakubpawlowicz/clean-css/issues/714) - stringifying property level at rules.
index b38b3f8..de148a0 100644 (file)
@@ -43,12 +43,15 @@ function mergeNonAdjacentByBody(tokens, options) {
     if (token[2].length > 0 && options.semanticMerging && isBemElement(token))
       removeAnyUnsafeElements(token, candidates);
 
-    var oldToken = candidates[stringifyBody(token[2])];
+    var candidateBody = stringifyBody(token[2]);
+    var oldToken = candidates[candidateBody];
     if (oldToken && !isSpecial(options, stringifySelectors(token[1])) && !isSpecial(options, stringifySelectors(oldToken[1]))) {
-      token[1] = cleanUpSelectors(oldToken[1].concat(token[1]), false, adjacentSpace);
+      token[1] = token[2].length > 0 ?
+        cleanUpSelectors(oldToken[1].concat(token[1]), false, adjacentSpace) :
+        oldToken[1].concat(token[1]);
 
       oldToken[2] = [];
-      candidates[stringifyBody(token[2])] = null;
+      candidates[candidateBody] = null;
     }
 
     candidates[stringifyBody(token[2])] = token;