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

Delta Between Two Patch Sets: lib/filterClasses.js

Issue 29550598: Issue 5735 - Use JS Map instead of Object for Filter.knownFilters (Closed) Base URL: https://github.com/adblockplus/adblockpluscore.git
Left Patch Set: address comments Created Sept. 20, 2017, 9:21 a.m.
Right Patch Set: address comments Created Sept. 20, 2017, 11:31 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 | « no previous file | lib/filterStorage.js » ('j') | 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-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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 }, 72 },
73 73
74 toString() 74 toString()
75 { 75 {
76 return this.text; 76 return this.text;
77 } 77 }
78 }; 78 };
79 79
80 /** 80 /**
81 * Cache for known filters, maps string representation to filter objects. 81 * Cache for known filters, maps string representation to filter objects.
82 * @type {Object} 82 * @type {Map.<string,Filter>}
Wladimir Palant 2017/09/20 11:00:27 Actually, this needs to be adjusted - type should
sergei 2017/09/20 11:31:27 Done.
83 */ 83 */
84 Filter.knownFilters = new Map(); 84 Filter.knownFilters = new Map();
85 85
86 /** 86 /**
87 * Regular expression that element hiding filters should match 87 * Regular expression that element hiding filters should match
88 * @type {RegExp} 88 * @type {RegExp}
89 */ 89 */
90 Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/; 90 Filter.elemhideRegExp = /^([^/*|@"!]*?)#([@?])?#(.+)$/;
91 /** 91 /**
92 * Regular expression that RegExp filters specified as RegExps should match 92 * Regular expression that RegExp filters specified as RegExps should match
93 * @type {RegExp} 93 * @type {RegExp}
94 */ 94 */
95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/; 95 Filter.regexpRegExp = /^(@@)?\/.*\/(?:\$~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^, \s]+)?)*)?$/;
96 /** 96 /**
97 * Regular expression that options on a RegExp filter should match 97 * Regular expression that options on a RegExp filter should match
98 * @type {RegExp} 98 * @type {RegExp}
99 */ 99 */
100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/; 100 Filter.optionsRegExp = /\$(~?[\w-]+(?:=[^,\s]+)?(?:,~?[\w-]+(?:=[^,\s]+)?)*)$/;
101 101
102 /** 102 /**
103 * Creates a filter of correct type from its text representation - does the 103 * Creates a filter of correct type from its text representation - does the
104 * basic parsing and calls the right constructor then. 104 * basic parsing and calls the right constructor then.
105 * 105 *
106 * @param {string} text as in Filter() 106 * @param {string} text as in Filter()
107 * @return {Filter} 107 * @return {Filter}
108 */ 108 */
109 Filter.fromText = function(text) 109 Filter.fromText = function(text)
110 { 110 {
111 let ret = Filter.knownFilters.get(text); 111 let ret = Filter.knownFilters.get(text);
Wladimir Palant 2017/09/20 10:04:13 Nit: maybe a more meaningful name for this variabl
sergei 2017/09/20 10:27:33 I think it's not for this change because `ret` is
Wladimir Palant 2017/09/20 10:58:00 I see.
kzar 2017/09/20 12:30:24 Yea I think so, if you don't want to just give it
sergei 2017/09/20 13:12:45 Done in https://codereview.adblockplus.org/2955066
112 if (ret) 112 if (ret)
kzar 2017/09/20 12:30:24 Just an observation since I don't think it matters
113 return ret; 113 return ret;
114 114
115 let match = (text.includes("#") ? Filter.elemhideRegExp.exec(text) : null); 115 let match = (text.includes("#") ? Filter.elemhideRegExp.exec(text) : null);
116 if (match) 116 if (match)
117 { 117 {
118 let propsMatch; 118 let propsMatch;
119 if (!match[2] && 119 if (!match[2] &&
120 (propsMatch = /\[-abp-properties=(["'])([^"']+)\1\]/.exec(match[3]))) 120 (propsMatch = /\[-abp-properties=(["'])([^"']+)\1\]/.exec(match[3])))
121 { 121 {
122 // This is legacy CSS properties syntax, convert to current syntax 122 // This is legacy CSS properties syntax, convert to current syntax
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 */ 1020 */
1021 function ElemHideEmulationFilter(text, domains, selector) 1021 function ElemHideEmulationFilter(text, domains, selector)
1022 { 1022 {
1023 ElemHideBase.call(this, text, domains, selector); 1023 ElemHideBase.call(this, text, domains, selector);
1024 } 1024 }
1025 exports.ElemHideEmulationFilter = ElemHideEmulationFilter; 1025 exports.ElemHideEmulationFilter = ElemHideEmulationFilter;
1026 1026
1027 ElemHideEmulationFilter.prototype = extend(ElemHideBase, { 1027 ElemHideEmulationFilter.prototype = extend(ElemHideBase, {
1028 type: "elemhideemulation" 1028 type: "elemhideemulation"
1029 }); 1029 });
LEFTRIGHT

Powered by Google App Engine
This is Rietveld