Cache last 100 getDomains for filterStyles
This commit is contained in:
parent
78c56352cb
commit
4a642f77a5
19
storage.js
19
storage.js
|
@ -37,6 +37,7 @@ var cachedStyles, prefs;
|
|||
byId: new Map(),
|
||||
filters: new Map(),
|
||||
regexps: new Map(),
|
||||
urlDomains: new Map(),
|
||||
mutex: {
|
||||
inProgress: false,
|
||||
onDone: [],
|
||||
|
@ -196,6 +197,14 @@ function filterStyles(options = {}) {
|
|||
: cached.styles;
|
||||
}
|
||||
|
||||
if (matchUrl && !cachedStyles.urlDomains.has(matchUrl)) {
|
||||
cachedStyles.urlDomains.set(matchUrl, getDomains(matchUrl));
|
||||
for (let i = cachedStyles.urlDomains.size - 100; i > 0; i--) {
|
||||
const firstKey = cachedStyles.urlDomains.keys().next().value;
|
||||
cachedStyles.urlDomains.delete(firstKey);
|
||||
}
|
||||
}
|
||||
|
||||
const styles = id === null
|
||||
? (code ? cachedStyles.list : cachedStyles.noCode)
|
||||
: [(cachedStyles.byId.get(id) || {})[code ? 'style' : 'noCode']];
|
||||
|
@ -457,11 +466,10 @@ function sectionAppliesToUrl(section, url) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
if (section.domains.length) {
|
||||
for (const domain of getDomains(url)) {
|
||||
if (section.domains.indexOf(domain) != -1) {
|
||||
return true;
|
||||
}
|
||||
const urlDomains = cachedStyles.urlDomains.get(url) || getDomains(url);
|
||||
for (const domain of urlDomains) {
|
||||
if (section.domains.indexOf(domain) != -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (const regexp of section.regexps) {
|
||||
|
@ -490,6 +498,7 @@ function isCheckbox(el) {
|
|||
return el.localName == 'input' && el.type == 'checkbox';
|
||||
}
|
||||
|
||||
|
||||
// js engine can't optimize the entire function if it contains try-catch
|
||||
// so we should keep it isolated from normal code in a minimal wrapper
|
||||
// Update: might get fixed in V8 TurboFan in the future
|
||||
|
|
Loading…
Reference in New Issue
Block a user