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

Unified Diff: lib/downloader.js

Issue 29743730: Issue 6559 - Use maps and sets where appropriate (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Revert logic in getUnconditionalFilterKeys Created April 6, 2018, 1:32 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 | lib/elemHide.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/downloader.js
===================================================================
--- a/lib/downloader.js
+++ b/lib/downloader.js
@@ -43,28 +43,29 @@
{
this.dataSource = dataSource;
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._timer.initWithCallback(() =>
{
this._timer.delay = checkInterval;
this._doCheck();
}, initialDelay, Ci.nsITimer.TYPE_REPEATING_SLACK);
- this._downloading = Object.create(null);
+ this._downloading = new Set();
};
Downloader.prototype =
{
/**
* Timer triggering the downloads.
* @type {nsITimer}
*/
_timer: null,
/**
- * Map containing the URLs of objects currently being downloaded as its keys.
+ * Set containing the URLs of objects currently being downloaded.
+ * @type {Set.<string>}
*/
_downloading: null,
/**
* Function that will yield downloadable objects on each check.
* @type {Function}
*/
dataSource: null,
@@ -177,17 +178,17 @@
/**
* Checks whether an address is currently being downloaded.
* @param {string} url
* @return {boolean}
*/
isDownloading(url)
{
- return url in this._downloading;
+ return this._downloading.has(url);
},
/**
* Starts downloading for an object.
* @param {Downloadable} downloadable
*/
download(downloadable)
{
@@ -296,26 +297,26 @@
Cu.reportError(e);
}
request.addEventListener("error", event =>
{
if (onShutdown.done)
return;
- delete this._downloading[downloadable.url];
+ this._downloading.delete(downloadable.url);
errorCallback("synchronize_connection_error");
}, false);
request.addEventListener("load", event =>
{
if (onShutdown.done)
return;
- delete this._downloading[downloadable.url];
+ this._downloading.delete(downloadable.url);
// Status will be 0 for non-HTTP requests
if (request.status && request.status != 200)
{
errorCallback("synchronize_connection_error");
return;
}
@@ -333,17 +334,17 @@
this._download(downloadable, redirects + 1);
}
}
);
});
request.send(null);
- this._downloading[downloadable.url] = true;
+ this._downloading.add(downloadable.url);
if (this.onDownloadStarted)
this.onDownloadStarted(downloadable);
},
/**
* Produces a soft and a hard expiration interval for a given supplied
* expiration interval.
* @param {number} interval
« no previous file with comments | « no previous file | lib/elemHide.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld