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

Unified Diff: lib/filterClasses.js

Issue 29871555: Issue 6916 - Avoid Set object for filters with only one subscription (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 1, 2018, 5:12 a.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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/filterClasses.js
===================================================================
--- a/lib/filterClasses.js
+++ b/lib/filterClasses.js
@@ -36,17 +36,17 @@
*
* @param {string} text string representation of the filter
* @constructor
*/
function Filter(text)
{
this.text = text;
- this._subscriptions = new Set();
+ this._subscriptions = null;
}
exports.Filter = Filter;
Filter.prototype =
{
/**
* String representation of the filter
* @type {string}
@@ -63,27 +63,56 @@
},
/**
* Yields filter subscriptions the filter belongs to
* @yields {Subscription}
*/
*subscriptions()
{
- yield* this._subscriptions;
+ if (this._subscriptions)
+ {
+ if (this._subscriptions instanceof Set)
+ yield* this._subscriptions;
+ else
+ yield this._subscriptions;
+ }
},
addSubscription(subscription)
{
- this._subscriptions.add(subscription);
+ if (this._subscriptions)
+ {
+ if (this._subscriptions instanceof Set)
+ this._subscriptions.add(subscription);
+ else if (subscription != this._subscriptions)
+ this._subscriptions = new Set([this._subscriptions, subscription]);
+ }
+ else
+ {
+ this._subscriptions = subscription;
+ }
},
removeSubscription(subscription)
{
- this._subscriptions.delete(subscription);
+ if (this._subscriptions)
+ {
+ if (this._subscriptions instanceof Set)
+ {
+ this._subscriptions.delete(subscription);
+
+ if (this._subscriptions.size == 1)
+ this._subscriptions = [...this._subscriptions][0];
+ }
+ else if (subscription == this._subscriptions)
+ {
+ this._subscriptions = null;
+ }
+ }
},
/**
* Serializes the filter to an array of strings for writing out on the disk.
* @param {string[]} buffer buffer to push the serialization results into
*/
serialize(buffer)
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld