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

Side by Side Diff: lib/filterClasses.js

Issue 29909576: [experiment] Issue 7045 - Optimize V8 memory layout of filter text Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Make domains parameter nullable and optional Created Oct. 15, 2018, 9:28 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 | lib/filterText.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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 /** 20 /**
21 * @fileOverview Definition of Filter class and its subclasses. 21 * @fileOverview Definition of Filter class and its subclasses.
22 */ 22 */
23 23
24 const {filterNotifier} = require("./filterNotifier"); 24 const {filterNotifier} = require("./filterNotifier");
25 const {extend} = require("./coreUtils"); 25 const {extend} = require("./coreUtils");
26 const {filterToRegExp} = require("./common"); 26 const {filterToRegExp} = require("./common");
27 const {optimizeContentFilterText,
28 optimizeRegExpFilterText} = require("./filterText");
27 29
28 /** 30 /**
29 * All known unique domain sources mapped to their parsed values. 31 * All known unique domain sources mapped to their parsed values.
30 * @type {Map.<string,Map.<string,boolean>>} 32 * @type {Map.<string,Map.<string,boolean>>}
31 */ 33 */
32 let knownDomainMaps = new Map(); 34 let knownDomainMaps = new Map();
33 35
34 /** 36 /**
35 * Abstract base class for filters 37 * Abstract base class for filters
36 * 38 *
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 if (rewrite != null) 890 if (rewrite != null)
889 { 891 {
890 if (contentType == null) 892 if (contentType == null)
891 ({contentType} = RegExpFilter.prototype); 893 ({contentType} = RegExpFilter.prototype);
892 contentType &= ~(RegExpFilter.typeMap.SCRIPT | 894 contentType &= ~(RegExpFilter.typeMap.SCRIPT |
893 RegExpFilter.typeMap.SUBDOCUMENT | 895 RegExpFilter.typeMap.SUBDOCUMENT |
894 RegExpFilter.typeMap.OBJECT | 896 RegExpFilter.typeMap.OBJECT |
895 RegExpFilter.typeMap.OBJECT_SUBREQUEST); 897 RegExpFilter.typeMap.OBJECT_SUBREQUEST);
896 } 898 }
897 899
900 [origText, text, domains, sitekeys, csp, rewrite] =
901 optimizeRegExpFilterText(origText, text, domains, sitekeys, csp, rewrite);
902
898 try 903 try
899 { 904 {
900 if (blocking) 905 if (blocking)
901 { 906 {
902 if (csp && Filter.invalidCSPRegExp.test(csp)) 907 if (csp && Filter.invalidCSPRegExp.test(csp))
903 return new InvalidFilter(origText, "filter_invalid_csp"); 908 return new InvalidFilter(origText, "filter_invalid_csp");
904 909
905 return new BlockingFilter(origText, text, contentType, matchCase, domains, 910 return new BlockingFilter(origText, text, contentType, matchCase, domains,
906 thirdParty, sitekeys, collapse, csp, rewrite); 911 thirdParty, sitekeys, collapse, csp, rewrite);
907 } 912 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 * ElemHideEmulationFilter|SnippetFilter|InvalidFilter} 1111 * ElemHideEmulationFilter|SnippetFilter|InvalidFilter}
1107 */ 1112 */
1108 ContentFilter.fromText = function(text, domains, type, body) 1113 ContentFilter.fromText = function(text, domains, type, body)
1109 { 1114 {
1110 // We don't allow content filters which have any empty domains. 1115 // We don't allow content filters which have any empty domains.
1111 // Note: The ContentFilter.prototype.domainSeparator is duplicated here, if 1116 // Note: The ContentFilter.prototype.domainSeparator is duplicated here, if
1112 // that changes this must be changed too. 1117 // that changes this must be changed too.
1113 if (domains && /(^|,)~?(,|$)/.test(domains)) 1118 if (domains && /(^|,)~?(,|$)/.test(domains))
1114 return new InvalidFilter(text, "filter_invalid_domain"); 1119 return new InvalidFilter(text, "filter_invalid_domain");
1115 1120
1121 [text, domains, type, body] =
1122 optimizeContentFilterText(text, domains, type, body);
1123
1116 if (type == "@") 1124 if (type == "@")
1117 return new ElemHideException(text, domains, body); 1125 return new ElemHideException(text, domains, body);
1118 1126
1119 if (type == "?" || type == "$") 1127 if (type == "?" || type == "$")
1120 { 1128 {
1121 // Element hiding emulation and snippet filters are inefficient so we need 1129 // Element hiding emulation and snippet filters are inefficient so we need
1122 // to make sure that they're only applied if they specify active domains 1130 // to make sure that they're only applied if they specify active domains
1123 if (!(/,[^~][^,.]*\.[^,]/.test("," + domains) || 1131 if (!(/,[^~][^,.]*\.[^,]/.test("," + domains) ||
1124 ("," + domains + ",").includes(",localhost,"))) 1132 ("," + domains + ",").includes(",localhost,")))
1125 { 1133 {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1245
1238 /** 1246 /**
1239 * Script that should be executed 1247 * Script that should be executed
1240 * @type {string} 1248 * @type {string}
1241 */ 1249 */
1242 get script() 1250 get script()
1243 { 1251 {
1244 return this.body; 1252 return this.body;
1245 } 1253 }
1246 }); 1254 });
OLDNEW
« no previous file with comments | « no previous file | lib/filterText.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld