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

Unified Diff: lib/elemHide.js

Issue 29935564: Issue 7452 - Do not cache element hiding filter objects by default Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase on GitLab MR #24 Created April 7, 2019, 6:08 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/filterClasses.js » ('j') | lib/filterClasses.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/elemHide.js
===================================================================
--- a/lib/elemHide.js
+++ b/lib/elemHide.js
@@ -16,16 +16,17 @@
*/
"use strict";
/**
* @fileOverview Element hiding implementation.
*/
+const {Filter} = require("./filterClasses");
Manish Jethani 2019/04/07 18:14:11 I have minimized the changes in this file for now
const {ElemHideExceptions} = require("./elemHideExceptions");
const {filterNotifier} = require("./filterNotifier");
const {normalizeHostname, domainSuffixes} = require("./url");
const {Cache} = require("./caching");
/**
* The maximum number of selectors in a CSS rule. This is used by
* <code>{@link createStyleSheet}</code> to split up a long list of selectors
@@ -129,17 +130,17 @@
{
// There's no need to note that a filter is generically disabled.
if (!isIncluded && domain == "")
continue;
let filters = filtersByDomain.get(domain);
if (!filters)
filtersByDomain.set(domain, filters = new Map());
- filters.set(filter, isIncluded);
+ filters.set(filter.text, isIncluded ? filter.selector : null);
}
}
/**
* Returns a list of selectors that apply on each website unconditionally.
* @returns {string[]}
*/
function getUnconditionalSelectors()
@@ -166,30 +167,26 @@
let excluded = new Set();
for (let currentDomain of domainSuffixes(domain, !specificOnly))
{
let filters = filtersByDomain.get(currentDomain);
if (filters)
{
- for (let [filter, isIncluded] of filters)
+ for (let [text, selector] of filters)
{
- if (!isIncluded)
+ if (!selector)
{
- excluded.add(filter);
+ excluded.add(text);
}
- else
+ else if ((excluded.size == 0 || !excluded.has(text)) &&
+ !ElemHideExceptions.getException(selector, domain))
{
- let {selector} = filter;
- if ((excluded.size == 0 || !excluded.has(filter)) &&
- !ElemHideExceptions.getException(selector, domain))
- {
- selectors.push(selector);
- }
+ selectors.push(selector);
}
}
}
}
return selectors;
}
@@ -212,33 +209,30 @@
let excluded = new Set();
for (let currentDomain of domainSuffixes(domain, !specificOnly))
{
let filters = filtersByDomain.get(currentDomain);
if (filters)
{
- for (let [filter, isIncluded] of filters)
+ for (let [text, selector] of filters)
{
- if (!isIncluded)
- {
- excluded.add(filter);
- }
- else if (excluded.size == 0 || !excluded.has(filter))
+ if (!selector)
{
- {
- let {selector} = filter;
- let exception = ElemHideExceptions.getException(selector, domain);
+ excluded.add(text);
+ }
+ else if (excluded.size == 0 || !excluded.has(text))
+ {
+ let exception = ElemHideExceptions.getException(selector, domain);
- if (exception)
- exceptions.push(exception);
- else
- selectors.push(selector);
- }
+ if (exception)
+ exceptions.push(exception);
+ else
+ selectors.push(selector);
}
}
}
}
return {selectors, exceptions};
}
@@ -304,17 +298,18 @@
}
}
// If this is the first exception for a previously unconditionally applied
// element hiding selector we need to take care to update the lookups.
let unconditionalFilterForSelector = filterBySelector.get(selector);
if (unconditionalFilterForSelector)
{
- addToFiltersByDomain(unconditionalFilterForSelector);
+ addToFiltersByDomain(Filter.fromText(unconditionalFilterForSelector,
+ false));
filterBySelector.delete(selector);
unconditionalSelectors = null;
defaultStyleSheet = null;
}
});
/**
* Container for element hiding filters
@@ -341,80 +336,84 @@
},
/**
* Add a new element hiding filter
* @param {ElemHideFilter} filter
*/
add(filter)
{
- if (knownFilters.has(filter))
+ let {text} = filter;
+
+ if (knownFilters.has(text))
return;
styleSheetCache.clear();
commonStyleSheet = null;
let {domains, selector} = filter;
if (!(domains || ElemHideExceptions.hasExceptions(selector)))
{
// The new filter's selector is unconditionally applied to all domains
- filterBySelector.set(selector, filter);
+ filterBySelector.set(selector, text);
unconditionalSelectors = null;
defaultStyleSheet = null;
}
else
{
// The new filter's selector only applies to some domains
addToFiltersByDomain(filter, domains);
}
- knownFilters.add(filter);
+ knownFilters.add(text);
filterNotifier.emit("elemhideupdate");
},
/**
* Removes an element hiding filter
* @param {ElemHideFilter} filter
*/
remove(filter)
{
- if (!knownFilters.has(filter))
+ let {text} = filter;
+
+ if (!knownFilters.has(text))
return;
styleSheetCache.clear();
commonStyleSheet = null;
let {selector} = filter;
// Unconditially applied element hiding filters
- if (filterBySelector.get(selector) == filter)
+ if (filterBySelector.get(selector) == text)
{
filterBySelector.delete(selector);
unconditionalSelectors = null;
defaultStyleSheet = null;
}
// Conditionally applied element hiding filters
else
{
let domains = filter.domains || defaultDomains;
for (let domain of domains.keys())
{
let filters = filtersByDomain.get(domain);
if (filters)
{
- filters.delete(filter);
+ filters.delete(text);
if (filters.size == 0)
filtersByDomain.delete(domain);
}
}
}
- knownFilters.delete(filter);
+ knownFilters.delete(text);
filterNotifier.emit("elemhideupdate");
},
/**
* @typedef {object} ElemHideStyleSheet
* @property {string} code CSS code.
* @property {Array.<string>} selectors List of selectors.
*/
« no previous file with comments | « no previous file | lib/filterClasses.js » ('j') | lib/filterClasses.js » ('J')

Powered by Google App Engine
This is Rietveld