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

Unified Diff: lib/subscriptionClasses.js

Issue 29800557: Issue 6559 - Use Map object for known subscriptions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created June 6, 2018, 10:50 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 | « lib/filterStorage.js ('k') | lib/synchronizer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/subscriptionClasses.js
===================================================================
--- a/lib/subscriptionClasses.js
+++ b/lib/subscriptionClasses.js
@@ -34,17 +34,17 @@
* @constructor
*/
function Subscription(url, title)
{
this.url = url;
this.filters = [];
if (title)
this._title = title;
- Subscription.knownSubscriptions[url] = this;
+ Subscription.knownSubscriptions.set(url, this);
}
exports.Subscription = Subscription;
Subscription.prototype =
{
/**
* Download location of the subscription
* @type {string}
@@ -149,31 +149,32 @@
let buffer = [];
this.serialize(buffer);
return buffer.join("\n");
}
};
/**
* Cache for known filter subscriptions, maps URL to subscription objects.
- * @type {Object}
+ * @type {Map.<string,Subscription>}
*/
-Subscription.knownSubscriptions = Object.create(null);
+Subscription.knownSubscriptions = new Map();
/**
* Returns a subscription from its URL, creates a new one if necessary.
* @param {string} url
* URL of the subscription
* @return {Subscription}
* subscription or null if the subscription couldn't be created
*/
Subscription.fromURL = function(url)
{
- if (url in Subscription.knownSubscriptions)
- return Subscription.knownSubscriptions[url];
+ let subscription = Subscription.knownSubscriptions.get(url);
+ if (subscription)
+ return subscription;
if (url[0] != "~")
return new DownloadableSubscription(url, null);
return new SpecialSubscription(url);
};
/**
* Deserializes a subscription
@@ -301,17 +302,17 @@
* @return {SpecialSubscription}
*/
SpecialSubscription.create = function(title)
{
let url;
do
{
url = "~user~" + Math.round(Math.random() * 1000000);
- } while (url in Subscription.knownSubscriptions);
+ } while (Subscription.knownSubscriptions.has(url));
return new SpecialSubscription(url, title);
};
/**
* Creates a new user-defined filter group and adds the given filter to it.
* This group will act as the default group for this filter type.
* @param {Filter} filter
* @return {SpecialSubscription}
« no previous file with comments | « lib/filterStorage.js ('k') | lib/synchronizer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld