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

Unified Diff: lib/elemHide.js

Issue 29342974: Issue 4067 - Make filter "keys" generated for element hiding filters numeric (Closed)
Patch Set: Fixed remaining addFilter calls Created May 24, 2016, 12:40 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 | lib/filterListener.js » ('j') | 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
@@ -26,17 +26,17 @@ var {IO} = require("io");
var {Prefs} = require("prefs");
var {ElemHideException} = require("filterClasses");
var {FilterNotifier} = require("filterNotifier");
/**
* Lookup table, filters by their associated key
* @type Object
*/
-var filterByKey = Object.create(null);
+var filterByKey = [];
/**
* Lookup table, keys of the filters by filter text
* @type Object
*/
var keyByFilter = Object.create(null);
/**
@@ -111,17 +111,17 @@ var ElemHide = exports.ElemHide =
styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL);
},
/**
* Removes all known filters
*/
clear: function()
{
- filterByKey = Object.create(null);
+ filterByKey = [];
keyByFilter = Object.create(null);
filtersByDomain = Object.create(null);
knownExceptions = Object.create(null);
exceptions = Object.create(null);
ElemHide.isDirty = false;
ElemHide.unapply();
},
@@ -142,22 +142,17 @@ var ElemHide = exports.ElemHide =
exceptions[selector].push(filter);
knownExceptions[filter.text] = true;
}
else
{
if (filter.text in keyByFilter)
return;
- let key;
- do {
- key = Math.random().toFixed(15).substr(5);
- } while (key in filterByKey);
-
- filterByKey[key] = filter;
+ let key = filterByKey.push(filter) - 1;
keyByFilter[filter.text] = key;
if (usingFiltersByDomain)
{
let domains = filter.domains || defaultDomains;
for (let domain in domains)
{
let filters = filtersByDomain[domain];
@@ -329,27 +324,31 @@ var ElemHide = exports.ElemHide =
_generateCSSContent: function*()
{
// Grouping selectors by domains
let domains = Object.create(null);
let hasFilters = false;
for (let key in filterByKey)
{
let filter = filterByKey[key];
+ let selector = filter.selector;
+ if (!selector)
+ continue;
+
let domain = filter.selectorDomain || "";
let list;
if (domain in domains)
list = domains[domain];
else
{
list = Object.create(null);
domains[domain] = list;
}
- list[filter.selector] = key;
+ list[selector] = key;
hasFilters = true;
}
if (!hasFilters)
throw Cr.NS_ERROR_NOT_AVAILABLE;
function escapeChar(match)
{
« no previous file with comments | « no previous file | lib/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld