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: Created Oct. 15, 2018, 5:04 a.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 if (domains)
901 {
902 [origText, text, domains, sitekeys, csp, rewrite] =
903 optimizeRegExpFilterText(origText, text, domains, sitekeys, csp, rewrite);
904 }
905
898 try 906 try
899 { 907 {
900 if (blocking) 908 if (blocking)
901 { 909 {
902 if (csp && Filter.invalidCSPRegExp.test(csp)) 910 if (csp && Filter.invalidCSPRegExp.test(csp))
903 return new InvalidFilter(origText, "filter_invalid_csp"); 911 return new InvalidFilter(origText, "filter_invalid_csp");
904 912
905 return new BlockingFilter(origText, text, contentType, matchCase, domains, 913 return new BlockingFilter(origText, text, contentType, matchCase, domains,
906 thirdParty, sitekeys, collapse, csp, rewrite); 914 thirdParty, sitekeys, collapse, csp, rewrite);
907 } 915 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 * ElemHideEmulationFilter|SnippetFilter|InvalidFilter} 1114 * ElemHideEmulationFilter|SnippetFilter|InvalidFilter}
1107 */ 1115 */
1108 ContentFilter.fromText = function(text, domains, type, body) 1116 ContentFilter.fromText = function(text, domains, type, body)
1109 { 1117 {
1110 // We don't allow content filters which have any empty domains. 1118 // We don't allow content filters which have any empty domains.
1111 // Note: The ContentFilter.prototype.domainSeparator is duplicated here, if 1119 // Note: The ContentFilter.prototype.domainSeparator is duplicated here, if
1112 // that changes this must be changed too. 1120 // that changes this must be changed too.
1113 if (domains && /(^|,)~?(,|$)/.test(domains)) 1121 if (domains && /(^|,)~?(,|$)/.test(domains))
1114 return new InvalidFilter(text, "filter_invalid_domain"); 1122 return new InvalidFilter(text, "filter_invalid_domain");
1115 1123
1124 if (domains)
1125 {
1126 [text, domains, type, body] =
1127 optimizeContentFilterText(text, domains, type, body);
1128 }
1129
1116 if (type == "@") 1130 if (type == "@")
1117 return new ElemHideException(text, domains, body); 1131 return new ElemHideException(text, domains, body);
1118 1132
1119 if (type == "?" || type == "$") 1133 if (type == "?" || type == "$")
1120 { 1134 {
1121 // Element hiding emulation and snippet filters are inefficient so we need 1135 // 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 1136 // to make sure that they're only applied if they specify active domains
1123 if (!(/,[^~][^,.]*\.[^,]/.test("," + domains) || 1137 if (!(/,[^~][^,.]*\.[^,]/.test("," + domains) ||
1124 ("," + domains + ",").includes(",localhost,"))) 1138 ("," + domains + ",").includes(",localhost,")))
1125 { 1139 {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 1251
1238 /** 1252 /**
1239 * Script that should be executed 1253 * Script that should be executed
1240 * @type {string} 1254 * @type {string}
1241 */ 1255 */
1242 get script() 1256 get script()
1243 { 1257 {
1244 return this.body; 1258 return this.body;
1245 } 1259 }
1246 }); 1260 });
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