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

Unified Diff: lib/elemHide.js

Issue 29353428: Noissue - Simplify unconditional selector lookup (Closed)
Patch Set: Created Sept. 20, 2016, 9:22 a.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
diff --git a/lib/elemHide.js b/lib/elemHide.js
index 265d611942817dfb7412e528086546d6d20d3dd1..1aed855cbf18fb3505ff4046179cba56e6582ba4 100644
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -43,23 +43,22 @@ var keyByFilter = Object.create(null);
var filtersByDomain = Object.create(null);
/**
- * Lookup table, filter keys by selector. (Only contains filters that have a
+ * Lookup table, filter key by selector. (Only contains filters that have a
* selector that is unconditionally matched for all domains.)
*/
-var filterKeysBySelector = Object.create(null);
+var filterKeyBySelector = Object.create(null);
/**
- * This array caches the keys of filterKeysBySelector table (selectors which
+ * This array caches the keys of filterKeyBySelector table (selectors which
* unconditionally apply on all domains). It will be null if the cache needs to
* be rebuilt.
*/
var unconditionalSelectors = null;
/**
- * This array caches the values of filterKeysBySelector table (filterIds for
+ * This array caches the values of filterKeyBySelector table (filterIds for
* selectors which unconditionally apply on all domains). It will be null if the
- * cache needs to be rebuilt. Note: Only the first filter key for each selector
- * is cached.
+ * cache needs to be rebuilt.
*/
var unconditionalFilterKeys = null;
@@ -95,7 +94,7 @@ var ElemHide = exports.ElemHide =
filterByKey = [];
keyByFilter = Object.create(null);
filtersByDomain = Object.create(null);
- filterKeysBySelector = Object.create(null);
+ filterKeyBySelector = Object.create(null);
unconditionalSelectors = unconditionalFilterKeys = null;
knownExceptions = Object.create(null);
exceptions = Object.create(null);
@@ -137,13 +136,11 @@ var ElemHide = exports.ElemHide =
// If this is the first exception for a previously unconditionally
// applied element hiding selector we need to take care to update the
// lookups.
- let filterKeys = filterKeysBySelector[selector];
- if (filterKeys)
+ let filterKey = filterKeyBySelector[selector];
+ if (filterKey)
{
- for (let filterKey of filterKeys)
- this._addToFiltersByDomain(filterKey, filterByKey[filterKey]);
- delete filterKeysBySelector[selector];
- unconditionalSelectors = unconditionalFilterKeys = null;
+ this._addToFiltersByDomain(filterKey, filterByKey[filterKey]);
+ delete filterKeyBySelector[selector];
}
knownExceptions[filter.text] = true;
@@ -159,16 +156,8 @@ var ElemHide = exports.ElemHide =
if (!(filter.domains || filter.selector in exceptions))
{
// The new filter's selector is unconditionally applied to all domains
- let filterKeys = filterKeysBySelector[filter.selector];
- if (filterKeys)
- {
- filterKeys.push(key);
- }
- else
- {
- filterKeysBySelector[filter.selector] = [key];
- unconditionalSelectors = unconditionalFilterKeys = null;
- }
+ filterKeyBySelector[filter.selector] = key;
+ unconditionalSelectors = unconditionalFilterKeys = null;
}
else
{
@@ -206,19 +195,10 @@ var ElemHide = exports.ElemHide =
delete filterByKey[key];
delete keyByFilter[filter.text];
- let filterKeys = filterKeysBySelector[filter.selector];
- if (filterKeys)
+ if (filter.selector in filterKeyBySelector)
{
- if (filterKeys.length > 1)
- {
- let index = filterKeys.indexOf(key);
- filterKeys.splice(index, 1);
- }
- else
- {
- delete filterKeysBySelector[filter.selector];
- unconditionalSelectors = unconditionalFilterKeys = null;
- }
+ delete filterKeyBySelector[filter.selector];
+ unconditionalSelectors = unconditionalFilterKeys = null;
}
else
{
@@ -294,7 +274,7 @@ var ElemHide = exports.ElemHide =
getUnconditionalSelectors: function()
{
if (!unconditionalSelectors)
- unconditionalSelectors = Object.keys(filterKeysBySelector);
+ unconditionalSelectors = Object.keys(filterKeyBySelector);
return unconditionalSelectors.slice();
},
@@ -311,7 +291,7 @@ var ElemHide = exports.ElemHide =
let selectors = this.getUnconditionalSelectors();
unconditionalFilterKeys = [];
for (let selector of selectors)
- unconditionalFilterKeys.push(filterKeysBySelector[selector][0]);
+ unconditionalFilterKeys.push(filterKeyBySelector[selector]);
}
return unconditionalFilterKeys.slice();
},
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld