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

Delta Between Two Patch Sets: lib/elemHide.js

Issue 4529242486341632: Issue 235 - Improved performance of ElemHide.getSelectorsForDomain() (Closed)
Left Patch Set: Couple of overall improvements Created June 23, 2015, 1:02 p.m.
Right Patch Set: Always consider generic filters Created July 2, 2015, 9:22 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/contentPolicy.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 */ 52 */
53 let exceptions = Object.create(null); 53 let exceptions = Object.create(null);
54 54
55 /** 55 /**
56 * Currently applied stylesheet URL 56 * Currently applied stylesheet URL
57 * @type nsIURI 57 * @type nsIURI
58 */ 58 */
59 let styleURL = null; 59 let styleURL = null;
60 60
61 /** 61 /**
62 * Lookup table, blocking filter selectors by domain which they are applied to 62 * Lookup table, filter selectors by domain which they are applied to
Wladimir Palant 2015/06/23 13:57:09 Nit: the word "blocking" makes no sense here.
Thomas Greiner 2015/07/02 09:32:49 Done.
63 * @type Object 63 * @type Object
64 */ 64 */
65 let selectorsByDomain = Object.create(null); 65 let selectorsByDomain = Object.create(null);
66 66
67 /** 67 /**
68 * Indicates whether stylesheets can be used for element hiding 68 * Indicates whether stylesheets can be used for element hiding
69 * @type Boolean 69 * @type Boolean
70 */ 70 */
71 let canUseStylesheets = ("nsIStyleSheetService" in Ci); 71 let canUseStylesheets = ("nsIStyleSheetService" in Ci);
72 72
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 let selectors = selectorsByDomain[domain]; 164 let selectors = selectorsByDomain[domain];
165 if (!(filter.selector in selectors)) 165 if (!(filter.selector in selectors))
166 { 166 {
167 selectors[filter.selector] = { 167 selectors[filter.selector] = {
168 isActive: false, 168 isActive: false,
169 count: 0 169 count: 0
170 }; 170 };
171 } 171 }
172 selectors[filter.selector].isActive |= domains[domain]; 172 selectors[filter.selector].isActive |= domains[domain];
Thomas Greiner 2015/06/23 13:28:41 I made this change here because I noticed that thi
Wladimir Palant 2015/06/23 13:57:09 Unfortunately, the result still isn't correct. Con
Thomas Greiner 2015/06/23 15:11:41 I see your point and please correct me if I'm wron
Wladimir Palant 2015/06/29 09:09:09 The problem is: you would create a behavior here t
Thomas Greiner 2015/06/29 13:03:44 Generally, I might be able to solve this by splitt
Thomas Greiner 2015/07/02 09:32:49 Done. See comment below for further details.
173 selectors[filter.selector].count++; 173 selectors[filter.selector].count++;
174 174
175 selectors.$length++; 175 selectors.$length++;
176 } 176 }
177 } 177 }
178 178
179 let key; 179 let key;
180 do { 180 do {
181 key = Math.random().toFixed(15).substr(5); 181 key = Math.random().toFixed(15).substr(5);
182 } while (key in filterByKey); 182 } while (key in filterByKey);
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 } 342 }
343 } 343 }
344 344
345 FilterNotifier.triggerListeners("elemhideupdate"); 345 FilterNotifier.triggerListeners("elemhideupdate");
346 } 346 }
347 }.bind(this)); 347 }.bind(this));
348 348
349 this._applying = true; 349 this._applying = true;
350 }, 350 },
351 351
352 _generateCSSContent: function*() 352 _generateCSSContent: function*()
Thomas Greiner 2015/06/23 13:28:41 This was added when rebasing
353 { 353 {
354 // Grouping selectors by domains 354 // Grouping selectors by domains
355 let domains = Object.create(null); 355 let domains = Object.create(null);
356 let hasFilters = false; 356 let hasFilters = false;
357 for (let key in filterByKey) 357 for (let key in filterByKey)
358 { 358 {
359 let filter = filterByKey[key]; 359 let filter = filterByKey[key];
360 let domain = filter.selectorDomain || ""; 360 let domain = filter.selectorDomain || "";
361 361
362 let list; 362 let list;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 440
441 /** 441 /**
442 * Returns a list of all selectors active on a particular domain (it cannot 442 * Returns a list of all selectors active on a particular domain (it cannot
443 * be used in Firefox). 443 * be used in Firefox).
444 */ 444 */
445 getSelectorsForDomain: function(/**String*/ docDomain, /**Boolean*/ specificOn ly) 445 getSelectorsForDomain: function(/**String*/ docDomain, /**Boolean*/ specificOn ly)
446 { 446 {
447 if (canUseStylesheets) 447 if (canUseStylesheets)
448 throw new Error("Use of getSelectorsForDomain is limited to platforms whic h cannot inject stylesheets"); 448 throw new Error("Use of getSelectorsForDomain is limited to platforms whic h cannot inject stylesheets");
449 449
450 let selectors = []; 450 let selectors = Object.create(null);
451 let domain = docDomain.toUpperCase(); 451 let domain = docDomain.toUpperCase();
452
453 let ignoredSelectors = Object.create(null);
454 while (true) 452 while (true)
455 { 453 {
456 if (domain in selectorsByDomain && (domain != "" || !specificOnly)) 454 if (domain in selectorsByDomain && (domain != "" || !specificOnly))
457 { 455 {
458 let domainSelectors = selectorsByDomain[domain]; 456 let domainSelectors = selectorsByDomain[domain];
459 let filterSelectors = Object.getOwnPropertyNames(domainSelectors); 457 let filterSelectors = Object.getOwnPropertyNames(domainSelectors);
460 for (let filterSelector of filterSelectors) 458 for (let filterSelector of filterSelectors)
461 { 459 {
462 if (filterSelector == "$length" || filterSelector in ignoredSelectors) 460 if (filterSelector == "$length"
461 || filterSelector in selectors
462 || !domainSelectors[filterSelector].isActive
463 || this.getException(filterSelector, docDomain))
463 continue; 464 continue;
Wladimir Palant 2015/07/30 11:26:53 Even with the inconsistent logic changes you are i
464 465
465 if (domainSelectors[filterSelector].isActive) 466 selectors[filterSelector] = null;
466 {
467 if (!this.getException(filterSelector, docDomain))
468 {
469 selectors.push(filterSelector);
470 ignoredSelectors[filterSelector] = null;
471 }
472 }
473 else
474 ignoredSelectors[filterSelector] = null;
Thomas Greiner 2015/07/02 09:32:49 Basically, all I did was remove the else-case here
475 } 467 }
476 } 468 }
477 469
478 if (domain == "") 470 if (domain == "")
479 break; 471 break;
480 472
481 let nextDot = domain.indexOf("."); 473 let nextDot = domain.indexOf(".");
482 domain = (nextDot < 0) ? "" : domain.substr(nextDot + 1); 474 domain = (nextDot < 0) ? "" : domain.substr(nextDot + 1);
483 } 475 }
484 476
485 return selectors; 477 return Object.getOwnPropertyNames(selectors);
486 } 478 }
487 }; 479 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld