Kaynağa Gözat

removed Array#find call

Gildas 7 yıl önce
ebeveyn
işleme
492f131180
1 değiştirilmiş dosya ile 11 ekleme ve 1 silme
  1. 11 1
      lib/single-file/css-rules-matcher.js

+ 11 - 1
lib/single-file/css-rules-matcher.js

@@ -85,7 +85,7 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 	function getMatchedElementsSelector(doc, cssRule, selector, selectorText, selectorsText, mediaInfo, ruleIndex, sheetIndex, matchedElementsCache, unmatchedSelectorsCache) {
 		let matchedElements = matchedElementsCache.get(selectorText);
 		if (!matchedElements) {
-			if (unmatchedSelectorsCache.find(selector => selectorText.startsWith(selector))) {
+			if (isUnmatchedSelector(selectorText, unmatchedSelectorsCache)) {
 				matchedElements = [];
 			} else {
 				matchedElements = doc.querySelectorAll(selectorText);
@@ -125,6 +125,16 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 		}
 	}
 
+	// if (unmatchedSelectorsCache.find(selector => selectorText.startsWith(selector))) {
+
+	function isUnmatchedSelector(selector, unmatchedSelectorsCache) {
+		let selectorIndex = 0;
+		while (selectorIndex < unmatchedSelectorsCache.length && !selector.startsWith(unmatchedSelectorsCache[selectorIndex])) {
+			selectorIndex++;
+		}
+		return selector.startsWith(unmatchedSelectorsCache[selectorIndex]);
+	}
+
 	function computeCascade(mediaInfo, parentMediaInfos, mediaAllInfo) {
 		mediaInfo.elements.forEach(elementInfo => getStylesInfo(elementInfo).forEach((elementStyleInfo, styleName) => {
 			let ruleInfo, ascendantMedia;