Bug 781588 - [Perf] Refactor formatValue to increase performance by 40%. r=felipe
authorJared Wein <jwein@mozilla.com>
Fri, 21 Sep 2012 16:03:23 -0700
changeset 107781 f753afbe0d85e49e52be57c6269c03ce3e30f51f
parent 107780 9108fa673bfee54a3611fd0c261134c51160b0d8
child 107782 1233552047f475bb011dd35f6ad59dcb63659678
push id23509
push userryanvm@gmail.com
push dateSat, 22 Sep 2012 12:28:38 +0000
treeherdermozilla-central@b461a7cd250e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe
bugs781588
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 781588 - [Perf] Refactor formatValue to increase performance by 40%. r=felipe Removed a couple of regular expressions from formatValue and replace them with simple string manipulation. The property access of this.editor was taking 5% of the formatValue function. Switching it to a field removes this extra overhead.
browser/base/content/urlbarBindings.xml
toolkit/content/widgets/textbox.xml
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -177,22 +177,26 @@
 
           let [, preDomain, domain] = matchedURL;
           let baseDomain = domain;
           let subDomain = "";
           // getBaseDomainFromHost doesn't recognize IPv6 literals in brackets as IPs (bug 667159)
           if (domain[0] != "[") {
             try {
               baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
+              if (!domain.contains(baseDomain)) {
+                // getBaseDomainFromHost converts its resultant to ACE.
+                let IDNService = Cc["@mozilla.org/network/idn-service;1"]
+                                 .getService(Ci.nsIIDNService);
+                baseDomain = IDNService.convertACEtoUTF8(baseDomain);
+              }
             } catch (e) {}
           }
           if (baseDomain != domain) {
-            let segments = function (s) s.replace(/[^.]*/g, "").length + 1;
-            let subSegments = segments(domain) - segments(baseDomain);
-            subDomain = domain.match(new RegExp("(?:[^.]*\.){" + subSegments + "}"))[0];
+            subDomain = domain.slice(0, -baseDomain.length);
           }
 
           let rangeLength = preDomain.length + subDomain.length;
           if (rangeLength) {
             let range = document.createRange();
             range.setStart(textNode, 0);
             range.setEnd(textNode, rangeLength);
             selection.addRange(range);
--- a/toolkit/content/widgets/textbox.xml
+++ b/toolkit/content/widgets/textbox.xml
@@ -87,22 +87,19 @@
                                          if (val) this.setAttribute('readonly', 'true');
                                          else this.removeAttribute('readonly'); return val;"
                                   onget="return this.inputField.readOnly;"/>
       <property name="clickSelectsAll"
                 onget="return this.getAttribute('clickSelectsAll') == 'true';"
                 onset="if (val) this.setAttribute('clickSelectsAll', 'true');
                        else this.removeAttribute('clickSelectsAll'); return val;" />
 
-      <property name="editor" readonly="true">
-        <getter><![CDATA[
-          const nsIDOMNSEditableElement = Components.interfaces.nsIDOMNSEditableElement;
-          return this.inputField.QueryInterface(nsIDOMNSEditableElement).editor;
-        ]]></getter>
-      </property>
+      <field name="editor" readonly="true">
+        this.inputField.QueryInterface(Components.interfaces.nsIDOMNSEditableElement).editor;
+      </field>
 
       <method name="reset">
         <body><![CDATA[
           this.value = this.defaultValue;
           try {
             this.editor.transactionManager.clear();
             return true;
           }
@@ -212,17 +209,17 @@
               return;
           }
           this.setAttribute("focused", "true");
         ]]>
       </handler>
 
       <handler event="blur" phase="capturing">
         <![CDATA[
-          this.removeAttribute('focused');
+          this.removeAttribute("focused");
 
           // don't trigger clickSelectsAll when switching application windows
           if (window == window.top &&
               window.constructor == ChromeWindow &&
               document.activeElement == this.inputField)
             this.mIgnoreFocus = true;
         ]]>
       </handler>