Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/elemHide.js

Issue 29892563: Issue 6989 - Optimize CSS rule generation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 26, 2018, 2:05 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -271,37 +271,41 @@
// this could still lead to some selectors not working on Chromium, but it is
// highly unlikely.
// See issue #6298 and https://crbug.com/804179
for (let i = 0; i < selectors.length; i += selectorGroupSize)
yield selectors.slice(i, i + selectorGroupSize);
}
/**
- * Creates element hiding CSS rules for a given list of selectors. Each rule
- * contains no more than the maximum number of selectors as determined by the
- * value of <code>{@link selectorGroupSize}</code>.
+ * Creates an element hiding CSS rule for a given list of selectors.
*
* @param {Array.<string>} selectors
- * @yields {string}
+ * @returns {string}
*/
-function* createRules(selectors)
+function createRule(selectors)
{
- for (let selectorGroup of splitSelectors(selectors))
- yield selectorGroup.join(", ") + " {display: none !important;}";
+ let rule = "";
+
+ for (let i = 0; i < selectors.length - 1; i++)
Manish Jethani 2018/09/26 15:29:56 I tried a few things here: 1. Used `for...of` a
hub 2018/09/26 16:49:11 Acknowledged.
+ rule += selectors[i] + ", ";
+
+ rule += selectors[selectors.length - 1] + " {display: none !important;}\n";
+
+ return rule;
}
/**
* Creates an element hiding CSS style sheet from a given list of selectors.
* @param {Array.<string>} selectors
* @returns {string}
*/
function createStyleSheet(selectors)
{
let styleSheet = "";
- for (let rule of createRules(selectors))
- styleSheet += rule + "\n";
+ for (let selectorGroup of splitSelectors(selectors))
+ styleSheet += createRule(selectorGroup);
return styleSheet;
}
exports.createStyleSheet = createStyleSheet;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld