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

Unified Diff: lib/filterStorage.js

Issue 29852555: Issue 6559 - Convert subscriptions property of Filter to a set (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Aug. 10, 2018, 2:12 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
« no previous file with comments | « lib/filterListener.js ('k') | test/filterListener.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterStorage.js
===================================================================
--- a/lib/filterStorage.js
+++ b/lib/filterStorage.js
@@ -205,36 +205,38 @@
* particular group that the filter should be added to
* @param {number} [position]
* position within the subscription at which the filter should be added
*/
addFilter(filter, subscription, position)
{
if (!subscription)
{
- if (filter.subscriptions.some(s => s instanceof SpecialSubscription &&
- !s.disabled))
+ for (let currentSubscription of filter.subscriptions)
{
- return; // No need to add
+ if (currentSubscription instanceof SpecialSubscription &&
+ !currentSubscription.disabled)
+ {
+ return; // No need to add
+ }
}
subscription = FilterStorage.getGroupForFilter(filter);
}
if (!subscription)
{
// No group for this filter exists, create one
subscription = SpecialSubscription.createForFilter(filter);
this.addSubscription(subscription);
return;
}
if (typeof position == "undefined")
position = subscription.filters.length;
- if (filter.subscriptions.indexOf(subscription) < 0)
- filter.subscriptions.push(subscription);
+ filter.subscriptions.add(subscription);
subscription.filters.splice(position, 0, filter);
FilterNotifier.triggerListeners("filter.added", filter, subscription,
position);
},
/**
* Removes a user-defined filter from the list
* @param {Filter} filter
@@ -242,21 +244,20 @@
* the filter should be removed from (if ommited will be removed from all
* subscriptions)
* @param {number} [position] position inside the filter group at which the
* filter should be removed (if ommited all instances will be removed)
*/
removeFilter(filter, subscription, position)
{
let subscriptions = (
- subscription ? [subscription] : filter.subscriptions.slice()
+ subscription ? [subscription] : filter.subscriptions
);
- for (let i = 0; i < subscriptions.length; i++)
+ for (let currentSubscription of subscriptions)
{
- let currentSubscription = subscriptions[i];
if (currentSubscription instanceof SpecialSubscription)
{
let positions = [];
if (typeof position == "undefined")
{
let index = -1;
do
{
@@ -270,21 +271,17 @@
for (let j = positions.length - 1; j >= 0; j--)
{
let currentPosition = positions[j];
if (currentSubscription.filters[currentPosition] == filter)
{
currentSubscription.filters.splice(currentPosition, 1);
if (currentSubscription.filters.indexOf(filter) < 0)
- {
- let index = filter.subscriptions.indexOf(currentSubscription);
- if (index >= 0)
- filter.subscriptions.splice(index, 1);
- }
+ filter.subscriptions.delete(currentSubscription);
FilterNotifier.triggerListeners(
"filter.removed", filter, currentSubscription, currentPosition
);
}
}
}
}
},
@@ -657,35 +654,31 @@
* filter subscription that should be connected to its filters
*/
function addSubscriptionFilters(subscription)
{
if (!FilterStorage.knownSubscriptions.has(subscription.url))
return;
for (let filter of subscription.filters)
- filter.subscriptions.push(subscription);
+ filter.subscriptions.add(subscription);
}
/**
* Removes subscription's filters from the subscription without any
* notifications.
* @param {Subscription} subscription filter subscription to be removed
*/
function removeSubscriptionFilters(subscription)
{
if (!FilterStorage.knownSubscriptions.has(subscription.url))
return;
for (let filter of subscription.filters)
- {
- let i = filter.subscriptions.indexOf(subscription);
- if (i >= 0)
- filter.subscriptions.splice(i, 1);
- }
+ filter.subscriptions.delete(subscription);
}
/**
* Listener returned by FilterStorage.importData(), parses filter data.
* @constructor
*/
function INIParser()
{
@@ -738,17 +731,17 @@
{
let subscription = this.subscriptions[
this.subscriptions.length - 1
];
for (let text of this.curObj)
{
let filter = Filter.fromText(text);
subscription.filters.push(filter);
- filter.subscriptions.push(subscription);
+ filter.subscriptions.add(subscription);
}
}
break;
}
}
if (val === null)
return;
« no previous file with comments | « lib/filterListener.js ('k') | test/filterListener.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld