From 787ec862755b189be89eab49f672fab30f5ba212 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 3 Jan 2016 15:15:18 +0000 Subject: [PATCH] Speeds up merging by body advanced optimization. Testing #715 revealed `mergeNonAdjacentByBody` spends lots of time optimizing selectors with empty body, which, at the end, will be removed. --- History.md | 1 + lib/selectors/merge-non-adjacent-by-body.js | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/History.md b/History.md index 882a53c4..28fcfe60 100644 --- a/History.md +++ b/History.md @@ -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. diff --git a/lib/selectors/merge-non-adjacent-by-body.js b/lib/selectors/merge-non-adjacent-by-body.js index b38b3f89..de148a03 100644 --- a/lib/selectors/merge-non-adjacent-by-body.js +++ b/lib/selectors/merge-non-adjacent-by-body.js @@ -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; -- 2.34.1