Gildas 7 лет назад
Родитель
Сommit
2471e48060
1 измененных файлов с 9 добавлено и 9 удалено
  1. 9 9
      lib/single-file/css-rules-matcher.js

+ 9 - 9
lib/single-file/css-rules-matcher.js

@@ -88,11 +88,11 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 	function getMatchedElementsSelector(doc, cssRule, selector, selectorText, selectorsText, mediaInfo, ruleIndex, sheetIndex, matchedElementsCache, unmatchedSelectorsCache) {
 		let matchedElements = matchedElementsCache[selectorText];
 		if (!matchedElements) {
-			let selectorIndex = 0;
-			while (selectorIndex < unmatchedSelectorsCache.length && !selectorText.startsWith(unmatchedSelectorsCache[selectorIndex])) {
+			let selectorIndex = 0, selectorsLength = unmatchedSelectorsCache.length, unmatchedSelector;
+			while (selectorIndex < selectorsLength && !(unmatchedSelector = selectorText.startsWith(unmatchedSelectorsCache[selectorIndex]))) {
 				selectorIndex++;
 			}
-			if (selectorIndex < unmatchedSelectorsCache.length && selectorText.startsWith(unmatchedSelectorsCache[selectorIndex])) {
+			if (selectorIndex < selectorsLength && unmatchedSelector) {
 				matchedElements = [];
 			} else {
 				matchedElements = doc.querySelectorAll(selectorText);
@@ -112,11 +112,11 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 		const { elementInfo, ruleInfo, specificity } = info;
 		if (ruleInfo) {
 			if (compareSpecificity(ruleInfo.specificity, specificity) == 1) {
-				let pseudoClassIndex = 0;
-				while (pseudoClassIndex < IGNORED_PSEUDO_CLASSES.length && !selectorText.includes(IGNORED_PSEUDO_CLASSES[pseudoClassIndex])) {
+				let pseudoClassIndex = 0, pseudoClassesLength = IGNORED_PSEUDO_CLASSES.length, ignoredPseudoClass;
+				while (pseudoClassIndex < pseudoClassesLength && !(ignoredPseudoClass = selectorText.includes(IGNORED_PSEUDO_CLASSES[pseudoClassIndex]))) {
 					pseudoClassIndex++;
 				}
-				if (pseudoClassIndex < IGNORED_PSEUDO_CLASSES.length && selectorText.includes(IGNORED_PSEUDO_CLASSES[pseudoClassIndex])) {
+				if (pseudoClassIndex < pseudoClassesLength && ignoredPseudoClass) {
 					ruleInfo.specificity = specificity;
 					ruleInfo.selectorText = selectorText;
 				}
@@ -143,11 +143,11 @@ this.RulesMatcher = this.RulesMatcher || (() => {
 		specificity.sheetIndex = sheetIndex;
 		let ruleInfo;
 		if (elementInfo.length) {
-			let elementRuleIndex = 0;
-			while (elementRuleIndex < elementInfo.length && elementInfo[elementRuleIndex].cssRule != cssRule) {
+			let elementRuleIndex = 0, elementRulesLength = elementInfo.length, cssRuleFound;
+			while (elementRuleIndex < elementRulesLength && !(cssRuleFound = elementInfo[elementRuleIndex].cssRule == cssRule)) {
 				elementRuleIndex++;
 			}
-			if (elementRuleIndex < elementInfo.length && elementInfo[elementRuleIndex].cssRule == cssRule) {
+			if (elementRuleIndex < elementRulesLength && cssRuleFound) {
 				ruleInfo = elementInfo[elementRuleIndex];
 			}
 		}