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

Side by Side Diff: lib/elemHide.js

Issue 29882558: Issue 6955 - Avoid making copies of common selector list (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 16, 2018, 4:07 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/elemHide.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 } 80 }
81 81
82 /** 82 /**
83 * Returns a list of selectors that apply on each website unconditionally. 83 * Returns a list of selectors that apply on each website unconditionally.
84 * @returns {string[]} 84 * @returns {string[]}
85 */ 85 */
86 function getUnconditionalSelectors() 86 function getUnconditionalSelectors()
87 { 87 {
88 if (!unconditionalSelectors) 88 if (!unconditionalSelectors)
89 unconditionalSelectors = [...filterBySelector.keys()]; 89 unconditionalSelectors = Object.freeze([...filterBySelector.keys()]);
90 90
91 return unconditionalSelectors; 91 return unconditionalSelectors;
92 } 92 }
93 93
94 ElemHideExceptions.on("added", ({selector}) => 94 ElemHideExceptions.on("added", ({selector}) =>
95 { 95 {
96 // If this is the first exception for a previously unconditionally applied 96 // If this is the first exception for a previously unconditionally applied
97 // element hiding selector we need to take care to update the lookups. 97 // element hiding selector we need to take care to update the lookups.
98 let unconditionalFilterForSelector = filterBySelector.get(selector); 98 let unconditionalFilterForSelector = filterBySelector.get(selector);
99 if (unconditionalFilterForSelector) 99 if (unconditionalFilterForSelector)
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 229 }
230 230
231 if (currentDomain == "") 231 if (currentDomain == "")
232 break; 232 break;
233 233
234 let nextDot = currentDomain.indexOf("."); 234 let nextDot = currentDomain.indexOf(".");
235 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); 235 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1);
236 } 236 }
237 237
238 if (!specificOnly) 238 if (!specificOnly)
239 selectors = getUnconditionalSelectors().concat(selectors); 239 {
240 // Avoid making a copy if there are no domain-specific selectors.
241 selectors = selectors.length > 0 ?
242 getUnconditionalSelectors().concat(selectors) :
243 getUnconditionalSelectors();
244 }
240 245
241 return selectors; 246 return selectors;
242 } 247 }
243 }; 248 };
OLDNEW
« no previous file with comments | « no previous file | test/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld