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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/subscriptionClasses.js
===================================================================
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -62,16 +62,23 @@
/**
* Filter text contained in the filter subscription.
* @type {Array.<string>}
* @private
*/
_filterText: null,
+ /**
+ * 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
+ * @type {?Set.<string>}
+ * @private
+ */
+ _filterTextIndex: null,
+
_title: null,
_fixedTitle: false,
_disabled: false,
/**
* Title of the filter subscription
* @type {string}
*/
@@ -142,83 +149,102 @@
* @yields {string}
*/
*filterText()
{
yield* this._filterText;
},
/**
+ * Checks whether the subscription has the given filter text.
+ * @param {string} filterText
+ * @returns {boolean}
+ * @package
+ */
+ hasFilterText(filterText)
+ {
+ if (!this._filterTextIndex)
Manish Jethani 2019/02/26 12:29:57 We build the index on first call. Unfortunately we
+ this._filterTextIndex = new Set(this._filterText);
+
+ return this._filterTextIndex.has(filterText);
+ },
+
+ /**
* Returns the filter text at the given 0-based index.
* @param {number} index
* @returns {?Filter}
*/
filterTextAt(index)
{
return this._filterText[index] || null;
},
/**
* Returns the 0-based index of the given filter.
* @param {Filter} filter
* @param {number} [fromIndex] The index from which to start the search.
* @return {number}
*/
- searchFilter(filter, fromIndex = 0)
+ findFilterIndex(filter, fromIndex = 0)
Manish Jethani 2019/02/26 12:29:57 While we're at it, let's rename this function to s
{
return this._filterText.indexOf(filter.text, fromIndex);
},
/**
* Removes all filters from the subscription.
*/
clearFilters()
{
this._filterText = [];
+ this._filterTextIndex = null;
},
/**
* Adds a filter to the subscription.
* @param {Filter} filter
*/
addFilter(filter)
{
this._filterText.push(filter.text);
+ 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
},
/**
* Adds a filter to the subscription.
* @param {string} filterText
*/
addFilterText(filterText)
{
this._filterText.push(filterText);
+ this._filterTextIndex = null;
},
/**
* Inserts a filter into the subscription.
* @param {Filter} filter
* @param {number} index The index at which to insert the filter.
*/
insertFilterAt(filter, index)
{
this._filterText.splice(index, 0, filter.text);
+ this._filterTextIndex = null;
},
/**
* Deletes a filter from the subscription.
* @param {number} index The index at which to delete the filter.
*/
deleteFilterAt(index)
{
// Ignore index if out of bounds on the negative side, for consistency.
if (index < 0)
return;
this._filterText.splice(index, 1);
+ this._filterTextIndex = null;
},
/**
* Serializes the subscription for writing out on disk.
* @yields {string}
*/
*serialize()
{

Powered by Google App Engine
This is Rietveld