Bug 723077 - Speed up processing of option elements in FormAssistant [r=wesj]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 10 Feb 2012 12:04:13 -0800
changeset 86632 a45cecfa8801feaae51e75c70587229255ebacb4
parent 86631 3852b3874127f06ac21d11189a6eb9e47e5e54b1
child 86633 b3f1f29ae19c07bf653257a09e25b9a93a637a1b
push idunknown
push userunknown
push dateunknown
reviewerswesj
bugs723077
milestone13.0a1
Bug 723077 - Speed up processing of option elements in FormAssistant [r=wesj]
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -2899,78 +2899,71 @@ var FormAssistant = {
       aElement.dispatchEvent(evt);
     }, 0);
   },
 
   _isSelectElement: function(aElement) {
     return (aElement instanceof HTMLSelectElement);
   },
 
-  _isOptionElement: function(aElement) {
-    return aElement instanceof HTMLOptionElement;
-  },
-
-  _isOptionGroupElement: function(aElement) {
-    return aElement instanceof HTMLOptGroupElement;
-  },
-
   getListForElement: function(aElement) {
     let result = {
       type: "Prompt:Show",
       multiple: aElement.multiple,
       selected: [],
       listitems: []
     };
 
     if (aElement.multiple) {
       result.buttons = [
         { label: Strings.browser.GetStringFromName("selectHelper.closeMultipleSelectDialog") },
       ];
     }
 
-    this.forOptions(aElement, function(aNode, aIndex) {
+    this.forOptions(aElement, function(aNode, aIndex, aIsGroup, aInGroup) {
       let item = {
         label: aNode.text || aNode.label,
-        isGroup: this._isOptionGroupElement(aNode),
-        inGroup: this._isOptionGroupElement(aNode.parentNode),
+        isGroup: aIsGroup,
+        inGroup: aInGroup,
         disabled: aNode.disabled,
         id: aIndex
       }
-      if (item.inGroup)
+      if (aInGroup)
         item.disabled = item.disabled || aNode.parentNode.disabled;
 
       result.listitems[aIndex] = item;
       result.selected[aIndex] = aNode.selected;
     });
     return result;
   },
 
   forOptions: function(aElement, aFunction) {
     let optionIndex = 0;
     let children = aElement.children;
+    let numChildren = children.length;
     // if there are no children in this select, we add a dummy row so that at least something appears
-    if (children.length == 0)
+    if (numChildren == 0)
       aFunction.call(this, {label:""}, optionIndex);
-    for (let i = 0; i < children.length; i++) {
+    for (let i = 0; i < numChildren; i++) {
       let child = children[i];
-      if (this._isOptionGroupElement(child)) {
-        aFunction.call(this, child, optionIndex);
+      if (child instanceof HTMLOptionElement) {
+        // This is a regular choice under no group.
+        aFunction.call(this, child, optionIndex, false, false);
+        optionIndex++;
+      } else if (child instanceof HTMLOptGroupElement) {
+        aFunction.call(this, child, optionIndex, true, false);
         optionIndex++;
 
         let subchildren = child.children;
-        for (let j = 0; j < subchildren.length; j++) {
+        let numSubchildren = subchildren.length;
+        for (let j = 0; j < numSubchildren; j++) {
           let subchild = subchildren[j];
-          aFunction.call(this, subchild, optionIndex);
+          aFunction.call(this, subchild, optionIndex, false, true);
           optionIndex++;
         }
-
-      } else if (this._isOptionElement(child)) {
-        // This is a regular choice under no group.
-        aFunction.call(this, child, optionIndex);
-        optionIndex++;
       }
     }
   }
 }
 
 var XPInstallObserver = {
   init: function xpi_init() {
     Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false);