From 31fb50a7468eb8c9a5b3aaa9845cc5614fe99abd Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Wed, 15 Feb 2012 15:07:30 +1300 Subject: [PATCH] Bug 714841 - With 30 lightweight themes installed, Add-ons Manager appearance pane is slow to load. r=dtownsend --- .../extensions/LightweightThemeManager.jsm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/toolkit/mozapps/extensions/LightweightThemeManager.jsm b/toolkit/mozapps/extensions/LightweightThemeManager.jsm index b7b5e51e4650..5075abe3f94f 100644 --- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm +++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm @@ -92,6 +92,8 @@ __defineSetter__("_maxUsedThemes", function(aVal) { return this._maxUsedThemes = aVal; }); +var _usedThemes = null; + // Holds the ID of the theme being enabled or disabled while sending out the // events so cached AddonWrapper instances can return correct values for // permissions and pendingOperations @@ -100,12 +102,16 @@ var _themeIDBeingDisbled = null; var LightweightThemeManager = { get usedThemes () { + if (_usedThemes) + return _usedThemes; + try { - return JSON.parse(_prefs.getComplexValue("usedThemes", - Ci.nsISupportsString).data); + _usedThemes = JSON.parse(_prefs.getComplexValue("usedThemes", + Ci.nsISupportsString).data); } catch (e) { - return []; + _usedThemes = []; } + return _usedThemes; }, get currentTheme () { @@ -408,7 +414,8 @@ var LightweightThemeManager = { return; } - aCallback([new AddonWrapper(a) for each (a in this.usedThemes)]); + let themes = this.usedThemes; + aCallback([new AddonWrapper(a) for each (a in themes)]); }, }; @@ -746,6 +753,10 @@ function _prefObserver(aSubject, aTopic, aData) { // Update the theme list to remove any themes over the number we keep _updateUsedThemes(LightweightThemeManager.usedThemes); break; + case "usedThemes": + // Clear the cache - it will be repopulated next time it's used. + _usedThemes = null; + break; } }