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: Rebase Created Sept. 1, 2018, 2:28 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 | « 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
@@ -38,20 +38,20 @@
* @constructor
*/
function Filter(text)
{
this.text = text;
/**
* Subscriptions to which this filter belongs.
- * @type {Set.<Subscription>}
+ * @type {(Subscription|Set.<Subscription>)?}
* @private
*/
- this._subscriptions = new Set();
+ this._subscriptions = null;
}
exports.Filter = Filter;
Filter.prototype =
{
/**
* String representation of the filter
* @type {string}
@@ -68,46 +68,78 @@
},
/**
* Yields subscriptions to which the filter belongs.
* @yields {Subscription}
*/
*subscriptions()
{
- yield* this._subscriptions;
+ if (this._subscriptions)
+ {
+ if (this._subscriptions instanceof Set)
+ yield* this._subscriptions;
+ else
+ yield this._subscriptions;
+ }
},
/**
* The number of subscriptions to which the filter belongs.
* @type {number}
*/
get subscriptionCount()
{
- return this._subscriptions.size;
+ if (this._subscriptions instanceof Set)
+ return this._subscriptions.size;
+
+ return this._subscriptions ? 1 : 0;
},
/**
* Adds a subscription to the set of subscriptions to which the filter
* belongs.
* @param {Subscription} subscription
*/
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;
+ }
},
/**
* Removes a subscription from the set of subscriptions to which the filter
* belongs.
* @param {Subscription} 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