From 0d77ab6b6561ae9cab8ffa69a65e0db490e14771 Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Mon, 22 Jul 2013 11:22:42 -0400 Subject: [PATCH] Bug 895778 - Optimize some of the code paths in CustomizableUIInternal.registerToolbar. r=Gijs r=mconley --- .../customizableui/src/CustomizableUI.jsm | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/browser/components/customizableui/src/CustomizableUI.jsm b/browser/components/customizableui/src/CustomizableUI.jsm index 7e24cc2134c..bd0e2f8a8f2 100644 --- a/browser/components/customizableui/src/CustomizableUI.jsm +++ b/browser/components/customizableui/src/CustomizableUI.jsm @@ -265,18 +265,14 @@ let CustomizableUIInternal = { registerToolbar: function(aToolbar) { let document = aToolbar.ownerDocument; let area = aToolbar.id; + let areaProperties = gAreas.get(area); - if (!gAreas.has(area)) { + if (!areaProperties) { throw new Error("Unknown customization area: " + area); } - if (this.isBuildAreaRegistered(area, aToolbar)) { - return; - } - - let areaProperties = gAreas.get(area); - - if (!gPlacements.has(area) && areaProperties.has("legacy")) { + let placements = gPlacements.get(area); + if (!placements && areaProperties.has("legacy")) { let legacyState = aToolbar.getAttribute("currentset"); if (legacyState) { legacyState = legacyState.split(",").filter(s => s); @@ -284,6 +280,7 @@ let CustomizableUIInternal = { // Manually restore the state here, so the legacy state can be converted. this.restoreStateForArea(area, legacyState); + placements = gPlacements.get(area); } if (areaProperties.has("overflowable")) { @@ -291,8 +288,6 @@ let CustomizableUIInternal = { } this.registerBuildArea(area, aToolbar); - - let placements = gPlacements.get(area); this.buildArea(area, placements, aToolbar); aToolbar.setAttribute("currentset", placements.join(",")); }, @@ -314,7 +309,7 @@ let CustomizableUIInternal = { for (let id of aPlacements) { if (currentNode && currentNode.id == id) { this._addParentFlex(currentNode); - this.setLocationAttributes(currentNode, container, aArea); + this.setLocationAttributes(currentNode, aArea); // Normalize removable attribute. It defaults to false if the widget is // originally defined as a child of a build area. @@ -371,7 +366,7 @@ let CustomizableUIInternal = { container.removeChild(node); } } else if (node.getAttribute("skipintoolbarset") != "true") { - this.setLocationAttributes(currentNode, container, aArea); + this.setLocationAttributes(currentNode, aArea); node.setAttribute("removable", false); LOG("Adding non-removable widget to placements of " + aArea + ": " + node.id); @@ -468,7 +463,8 @@ let CustomizableUIInternal = { }, registerMenuPanel: function(aPanel) { - if (this.isBuildAreaRegistered(CustomizableUI.AREA_PANEL, aPanel)) { + if (gBuildAreas.has(CustomizableUI.AREA_PANEL) && + gBuildAreas.get(CustomizableUI.AREA_PANEL).has(aPanel)) { return; } @@ -617,13 +613,6 @@ let CustomizableUIInternal = { } }, - isBuildAreaRegistered: function(aArea, aInstance) { - if (!gBuildAreas.has(aArea)) { - return false; - } - return gBuildAreas.get(aArea).has(aInstance); - }, - registerBuildArea: function(aArea, aNode) { // We ensure that the window is registered to have its customization data // cleaned up when unloading. @@ -677,7 +666,7 @@ let CustomizableUIInternal = { } }, - setLocationAttributes: function(aNode, aContainer, aArea) { + setLocationAttributes: function(aNode, aArea) { let props = gAreas.get(aArea); if (!props) { throw new Error("Expected area " + aArea + " to have a properties Map " + @@ -694,7 +683,7 @@ let CustomizableUIInternal = { }, insertWidgetBefore: function(aNode, aNextNode, aContainer, aArea) { - this.setLocationAttributes(aNode, aContainer, aArea); + this.setLocationAttributes(aNode, aArea); aContainer.insertBefore(aNode, aNextNode); }, @@ -1749,10 +1738,11 @@ let CustomizableUIInternal = { _addParentFlex: function(aElement) { // If necessary, add flex to accomodate new child. - if (aElement.hasAttribute("flex")) { + let elementFlex = aElement.getAttribute("flex"); + if (elementFlex) { let parent = aElement.parentNode; - let parentFlex = parent.hasAttribute("flex") ? parseInt(parent.getAttribute("flex"), 10) : 0; - let elementFlex = parseInt(aElement.getAttribute("flex"), 10); + let parentFlex = +parent.getAttribute("flex") || 0; + elementFlex = +elementFlex || 0; parent.setAttribute("flex", parentFlex + elementFlex); } },