Bug 834999 - WebappsApplication.prototype.manifest getter takes 25-30ms on critical startup path r=ferjm

This commit is contained in:
Fabrice Desré 2013-01-30 14:22:54 -08:00
parent 340ade1e4c
commit aca1391a5d

View File

@ -333,6 +333,26 @@ DOMError.prototype = {
* mozIDOMApplication object
*/
// A simple cache for the wrapped manifests.
let manifestCache = {
_cache: { },
// Gets an entry from the cache, and populates the cache if needed.
get : function mcache_get(aManifestURL, aManifest, aWindow) {
if (!(aManifestURL in this._cache)) {
this._cache[aManifestURL] = ObjectWrapper.wrap(aManifest, aWindow);
}
return this._cache[aManifestURL];
},
// Invalidates an entry in the cache.
evict: function mcache_evict(aManifestURL) {
if (aManifestURL in this._cache) {
delete this._cache[aManifestURL];
}
}
}
function createApplicationObject(aWindow, aApp) {
let app = Cc["@mozilla.org/webapps/application;1"].createInstance(Ci.mozIDOMApplication);
app.wrappedJSObject.init(aWindow, aApp);
@ -387,7 +407,7 @@ WebappsApplication.prototype = {
},
get manifest() {
return this.manifest = ObjectWrapper.wrap(this._manifest, this._window);
return manifestCache.get(this.manifestURL, this._manifest, this._window);
},
get updateManifest() {
@ -572,6 +592,7 @@ WebappsApplication.prototype = {
this._fireEvent("downloadprogress", this._onprogress);
break;
case "installed":
manifestCache.evict(this.manifestURL);
this._manifest = msg.manifest;
this._fireEvent("downloadsuccess", this._ondownloadsuccess);
this._fireEvent("downloadapplied", this._ondownloadapplied);
@ -580,11 +601,13 @@ WebappsApplication.prototype = {
// We don't update the packaged apps manifests until they
// are installed or until the update is unstaged.
if (msg.manifest) {
manifestCache.evict(this.manifestURL);
this._manifest = msg.manifest;
}
this._fireEvent("downloadsuccess", this._ondownloadsuccess);
break;
case "applied":
manifestCache.evict(this.manifestURL);
this._manifest = msg.manifest;
this._fireEvent("downloadapplied", this._ondownloadapplied);
break;