Bug 537290 - Reduce uses of aNode.localName, namespaceURI in XPath generation [r=zeniko]
authorPaul O’Shannessy <paul@oshannessy.com>
Tue, 05 Jan 2010 10:50:22 -0800
changeset 36958 ae840f6730727e4f0ee5c4701bb987445734ce44
parent 36957 314597526cbfc0d534c1dd283afcdf0e8b91d4ec
child 36959 36bd078ee596ed56c70272f58d929f1621bbfa75
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerszeniko
bugs537290
milestone1.9.3a1pre
Bug 537290 - Reduce uses of aNode.localName, namespaceURI in XPath generation [r=zeniko]
browser/components/sessionstore/src/nsSessionStore.js
--- a/browser/components/sessionstore/src/nsSessionStore.js
+++ b/browser/components/sessionstore/src/nsSessionStore.js
@@ -3005,29 +3005,33 @@ let XPathHelper = {
   /**
    * Generates an approximate XPath query to an (X)HTML node
    */
   generate: function sss_xph_generate(aNode) {
     // have we reached the document node already?
     if (!aNode.parentNode)
       return "";
     
-    let prefix = this.namespacePrefixes[aNode.namespaceURI] || null;
-    let tag = (prefix ? prefix + ":" : "") + this.escapeName(aNode.localName);
+    // Access localName, namespaceURI just once per node since it's expensive.
+    let nNamespaceURI = aNode.namespaceURI;
+    let nLocalName = aNode.localName;
+
+    let prefix = this.namespacePrefixes[nNamespaceURI] || null;
+    let tag = (prefix ? prefix + ":" : "") + this.escapeName(nLocalName);
     
     // stop once we've found a tag with an ID
     if (aNode.id)
       return "//" + tag + "[@id=" + this.quoteArgument(aNode.id) + "]";
     
     // count the number of previous sibling nodes of the same tag
     // (and possible also the same name)
     let count = 0;
     let nName = aNode.name || null;
     for (let n = aNode; (n = n.previousSibling); )
-      if (n.localName == aNode.localName && n.namespaceURI == aNode.namespaceURI &&
+      if (n.localName == nLocalName && n.namespaceURI == nNamespaceURI &&
           (!nName || n.name == nName))
         count++;
     
     // recurse until hitting either the document node or an ID'd node
     return this.generate(aNode.parentNode) + "/" + tag +
            (nName ? "[@name=" + this.quoteArgument(nName) + "]" : "") +
            (count ? "[" + (count + 1) + "]" : "");
   },