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

Side by Side Diff: lib/subscriptionClasses.js

Issue 30013628: Issue 7029 - Remove subscriptions property of Filter object (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 24, 2019, 1:30 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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 */ 60 */
61 type: null, 61 type: null,
62 62
63 /** 63 /**
64 * Filter text contained in the filter subscription. 64 * Filter text contained in the filter subscription.
65 * @type {Array.<string>} 65 * @type {Array.<string>}
66 * @private 66 * @private
67 */ 67 */
68 _filterText: null, 68 _filterText: null,
69 69
70 /**
71 * A searchable index of filter text in the filter subscription.
Manish Jethani 2019/02/26 12:29:57 We might be able to find a better way to do this t
72 * @type {?Set.<string>}
73 * @private
74 */
75 _filterTextIndex: null,
76
70 _title: null, 77 _title: null,
71 _fixedTitle: false, 78 _fixedTitle: false,
72 _disabled: false, 79 _disabled: false,
73 80
74 /** 81 /**
75 * Title of the filter subscription 82 * Title of the filter subscription
76 * @type {string} 83 * @type {string}
77 */ 84 */
78 get title() 85 get title()
79 { 86 {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 /** 147 /**
141 * Yields the text for each filter in the subscription. 148 * Yields the text for each filter in the subscription.
142 * @yields {string} 149 * @yields {string}
143 */ 150 */
144 *filterText() 151 *filterText()
145 { 152 {
146 yield* this._filterText; 153 yield* this._filterText;
147 }, 154 },
148 155
149 /** 156 /**
157 * Checks whether the subscription has the given filter text.
158 * @param {string} filterText
159 * @returns {boolean}
160 * @package
161 */
162 hasFilterText(filterText)
163 {
164 if (!this._filterTextIndex)
Manish Jethani 2019/02/26 12:29:57 We build the index on first call. Unfortunately we
165 this._filterTextIndex = new Set(this._filterText);
166
167 return this._filterTextIndex.has(filterText);
168 },
169
170 /**
150 * Returns the filter text at the given 0-based index. 171 * Returns the filter text at the given 0-based index.
151 * @param {number} index 172 * @param {number} index
152 * @returns {?Filter} 173 * @returns {?Filter}
153 */ 174 */
154 filterTextAt(index) 175 filterTextAt(index)
155 { 176 {
156 return this._filterText[index] || null; 177 return this._filterText[index] || null;
157 }, 178 },
158 179
159 /** 180 /**
160 * Returns the 0-based index of the given filter. 181 * Returns the 0-based index of the given filter.
161 * @param {Filter} filter 182 * @param {Filter} filter
162 * @param {number} [fromIndex] The index from which to start the search. 183 * @param {number} [fromIndex] The index from which to start the search.
163 * @return {number} 184 * @return {number}
164 */ 185 */
165 searchFilter(filter, fromIndex = 0) 186 findFilterIndex(filter, fromIndex = 0)
Manish Jethani 2019/02/26 12:29:57 While we're at it, let's rename this function to s
166 { 187 {
167 return this._filterText.indexOf(filter.text, fromIndex); 188 return this._filterText.indexOf(filter.text, fromIndex);
168 }, 189 },
169 190
170 /** 191 /**
171 * Removes all filters from the subscription. 192 * Removes all filters from the subscription.
172 */ 193 */
173 clearFilters() 194 clearFilters()
174 { 195 {
175 this._filterText = []; 196 this._filterText = [];
197 this._filterTextIndex = null;
176 }, 198 },
177 199
178 /** 200 /**
179 * Adds a filter to the subscription. 201 * Adds a filter to the subscription.
180 * @param {Filter} filter 202 * @param {Filter} filter
181 */ 203 */
182 addFilter(filter) 204 addFilter(filter)
183 { 205 {
184 this._filterText.push(filter.text); 206 this._filterText.push(filter.text);
207 this._filterTextIndex = null;
hub 2019/03/08 21:36:19 Shouldn't it be more efficiant that we add the `fi
Manish Jethani 2019/03/30 20:50:35 Adding it right away would mean more memory usage
185 }, 208 },
186 209
187 /** 210 /**
188 * Adds a filter to the subscription. 211 * Adds a filter to the subscription.
189 * @param {string} filterText 212 * @param {string} filterText
190 */ 213 */
191 addFilterText(filterText) 214 addFilterText(filterText)
192 { 215 {
193 this._filterText.push(filterText); 216 this._filterText.push(filterText);
217 this._filterTextIndex = null;
194 }, 218 },
195 219
196 /** 220 /**
197 * Inserts a filter into the subscription. 221 * Inserts a filter into the subscription.
198 * @param {Filter} filter 222 * @param {Filter} filter
199 * @param {number} index The index at which to insert the filter. 223 * @param {number} index The index at which to insert the filter.
200 */ 224 */
201 insertFilterAt(filter, index) 225 insertFilterAt(filter, index)
202 { 226 {
203 this._filterText.splice(index, 0, filter.text); 227 this._filterText.splice(index, 0, filter.text);
228 this._filterTextIndex = null;
204 }, 229 },
205 230
206 /** 231 /**
207 * Deletes a filter from the subscription. 232 * Deletes a filter from the subscription.
208 * @param {number} index The index at which to delete the filter. 233 * @param {number} index The index at which to delete the filter.
209 */ 234 */
210 deleteFilterAt(index) 235 deleteFilterAt(index)
211 { 236 {
212 // Ignore index if out of bounds on the negative side, for consistency. 237 // Ignore index if out of bounds on the negative side, for consistency.
213 if (index < 0) 238 if (index < 0)
214 return; 239 return;
215 240
216 this._filterText.splice(index, 1); 241 this._filterText.splice(index, 1);
242 this._filterTextIndex = null;
217 }, 243 },
218 244
219 /** 245 /**
220 * Serializes the subscription for writing out on disk. 246 * Serializes the subscription for writing out on disk.
221 * @yields {string} 247 * @yields {string}
222 */ 248 */
223 *serialize() 249 *serialize()
224 { 250 {
225 let {url, type, _title, _fixedTitle, _disabled} = this; 251 let {url, type, _title, _fixedTitle, _disabled} = this;
226 252
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 if (errors) 700 if (errors)
675 yield "errors=" + errors; 701 yield "errors=" + errors;
676 if (version) 702 if (version)
677 yield "version=" + version; 703 yield "version=" + version;
678 if (requiredVersion) 704 if (requiredVersion)
679 yield "requiredVersion=" + requiredVersion; 705 yield "requiredVersion=" + requiredVersion;
680 if (downloadCount) 706 if (downloadCount)
681 yield "downloadCount=" + downloadCount; 707 yield "downloadCount=" + downloadCount;
682 } 708 }
683 }); 709 });
OLDNEW

Powered by Google App Engine
This is Rietveld