Bug 455540. Eliminate the non-OOM-failures-possible version of GetNodInfo. r+sr=jst
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 07 Oct 2008 14:53:22 -0400
changeset 20105 18e5167ac65564a219d342adf2a10e4d79b95791
parent 20104 dadcc24af87a3f529cc6fced1c863e816c3a2f9f
child 20106 177b174c83e4bec7ff2deec35b5d827c716b7b6a
push idunknown
push userunknown
push dateunknown
bugs455540
milestone1.9.1b2pre
Bug 455540. Eliminate the non-OOM-failures-possible version of GetNodInfo. r+sr=jst
content/base/src/nsNodeInfoManager.cpp
content/base/src/nsNodeInfoManager.h
content/xul/document/public/nsIXULPrototypeCache.h
content/xul/document/src/nsXULPrototypeDocument.cpp
--- a/content/base/src/nsNodeInfoManager.cpp
+++ b/content/base/src/nsNodeInfoManager.cpp
@@ -257,55 +257,32 @@ nsNodeInfoManager::GetNodeInfo(const nsA
 {
   nsCOMPtr<nsIAtom> name = do_GetAtom(aName);
   *aNodeInfo = nsNodeInfoManager::GetNodeInfo(name, aPrefix, aNamespaceID).get();
   return *aNodeInfo ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 
 nsresult
-nsNodeInfoManager::GetNodeInfo(const nsAString& aQualifiedName,
+nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
                                const nsAString& aNamespaceURI,
                                nsINodeInfo** aNodeInfo)
 {
-  NS_ENSURE_ARG(!aQualifiedName.IsEmpty());
-
-  nsAString::const_iterator start, end;
-  aQualifiedName.BeginReading(start);
-  aQualifiedName.EndReading(end);
-
-  nsCOMPtr<nsIAtom> prefixAtom;
-
-  nsAString::const_iterator iter(start);
-
-  if (FindCharInReadable(':', iter, end)) {
-    prefixAtom = do_GetAtom(Substring(start, iter));
-    NS_ENSURE_TRUE(prefixAtom, NS_ERROR_OUT_OF_MEMORY);
-
-    start = ++iter; // step over the ':'
-
-    if (iter == end) {
-      // No data after the ':'.
-
-      return NS_ERROR_INVALID_ARG;
-    }
-  }
-
-  nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(Substring(start, end));
+  nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
   NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
 
   PRInt32 nsid = kNameSpaceID_None;
 
   if (!aNamespaceURI.IsEmpty()) {
     nsresult rv = nsContentUtils::NameSpaceManager()->
       RegisterNameSpace(aNamespaceURI, nsid);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
-  *aNodeInfo = GetNodeInfo(nameAtom, prefixAtom, nsid).get();
+  *aNodeInfo = GetNodeInfo(nameAtom, aPrefix, nsid).get();
   return *aNodeInfo ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 already_AddRefed<nsINodeInfo>
 nsNodeInfoManager::GetTextNodeInfo()
 {
   if (!mTextNodeInfo) {
     mTextNodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nsnull, kNameSpaceID_None).get();
--- a/content/base/src/nsNodeInfoManager.h
+++ b/content/base/src/nsNodeInfoManager.h
@@ -84,17 +84,17 @@ public:
 
   /**
    * Methods for creating nodeinfo's from atoms and/or strings.
    */
   already_AddRefed<nsINodeInfo> GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
                                             PRInt32 aNamespaceID);
   nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
                        PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo);
-  nsresult GetNodeInfo(const nsAString& aQualifiedName,
+  nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
                        const nsAString& aNamespaceURI,
                        nsINodeInfo** aNodeInfo);
 
   /**
    * Returns the nodeinfo for text nodes. Can return null if OOM.
    */
   already_AddRefed<nsINodeInfo> GetTextNodeInfo();
 
--- a/content/xul/document/public/nsIXULPrototypeCache.h
+++ b/content/xul/document/public/nsIXULPrototypeCache.h
@@ -77,15 +77,15 @@ NS_NewXULPrototypeCache(nsISupports* aOu
 
 
 const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL";
 
 // Increase the subtractor when changing version, say when changing the
 // (opaque to XPCOM FastLoad code) format of XUL-specific XDR serializations.
 // See also JSXDR_BYTECODE_VERSION in jsxdrapi.h, which tracks incompatible JS
 // bytecode version changes.
-#define XUL_FASTLOAD_FILE_VERSION       (0xfeedbeef - 24)
+#define XUL_FASTLOAD_FILE_VERSION       (0xfeedbeef - 25)
 
 #define XUL_SERIALIZATION_BUFFER_SIZE   (64 * 1024)
 #define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024)
 
 
 #endif // nsIXULPrototypeCache_h__
--- a/content/xul/document/src/nsXULPrototypeDocument.cpp
+++ b/content/xul/document/src/nsXULPrototypeDocument.cpp
@@ -302,23 +302,33 @@ nsXULPrototypeDocument::Read(nsIObjectIn
     mRoot = new nsXULPrototypeElement();
     if (! mRoot)
        return NS_ERROR_OUT_OF_MEMORY;
 
     // nsINodeInfo table
     nsCOMArray<nsINodeInfo> nodeInfos;
 
     rv |= aStream->Read32(&count);
-    nsAutoString namespaceURI, qualifiedName;
+    nsAutoString namespaceURI, prefixStr, localName;
+    PRBool prefixIsNull;
+    nsCOMPtr<nsIAtom> prefix;
     for (i = 0; i < count; ++i) {
         rv |= aStream->ReadString(namespaceURI);
-        rv |= aStream->ReadString(qualifiedName);
+        rv |= aStream->ReadBoolean(&prefixIsNull);
+        if (prefixIsNull) {
+            prefix = nsnull;
+        } else {
+            rv |= aStream->ReadString(prefixStr);
+            prefix = do_GetAtom(prefixStr);
+        }
+        rv |= aStream->ReadString(localName);
 
         nsCOMPtr<nsINodeInfo> nodeInfo;
-        rv |= mNodeInfoManager->GetNodeInfo(qualifiedName, namespaceURI, getter_AddRefs(nodeInfo));
+        rv |= mNodeInfoManager->GetNodeInfo(localName, prefix, namespaceURI,
+                                            getter_AddRefs(nodeInfo));
         if (!nodeInfos.AppendObject(nodeInfo))
             rv |= NS_ERROR_OUT_OF_MEMORY;
     }
 
     // Document contents
     PRUint32 type;
     while (NS_SUCCEEDED(rv)) {
         rv |= aStream->Read32(&type);
@@ -423,19 +433,27 @@ nsXULPrototypeDocument::Write(nsIObjectO
     for (i = 0; i < nodeInfoCount; ++i) {
         nsINodeInfo *nodeInfo = nodeInfos[i];
         NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE);
 
         nsAutoString namespaceURI;
         rv |= nodeInfo->GetNamespaceURI(namespaceURI);
         rv |= aStream->WriteWStringZ(namespaceURI.get());
 
-        nsAutoString qualifiedName;
-        nodeInfo->GetQualifiedName(qualifiedName);
-        rv |= aStream->WriteWStringZ(qualifiedName.get());
+        nsAutoString prefix;
+        nodeInfo->GetPrefix(prefix);
+        PRBool nullPrefix = DOMStringIsNull(prefix);
+        rv |= aStream->WriteBoolean(nullPrefix);
+        if (!nullPrefix) {
+            rv |= aStream->WriteWStringZ(prefix.get());
+        }
+
+        nsAutoString localName;
+        nodeInfo->GetName(localName);
+        rv |= aStream->WriteWStringZ(localName.get());
     }
 
     // Now serialize the document contents
     nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
     NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
 
     count = mProcessingInstructions.Length();
     for (i = 0; i < count; ++i) {