rdf-anonymous-resource-refcounting
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 117 1cf47cdb0feb0184e26baf4fe93127d2a286247f
permissions -rw-r--r--
State as of now

diff --git a/rdf/base/src/nsRDFService.cpp b/rdf/base/src/nsRDFService.cpp
--- a/rdf/base/src/nsRDFService.cpp
+++ b/rdf/base/src/nsRDFService.cpp
@@ -987,7 +987,7 @@ static PRInt32 kShift = 6;
     nsresult rv;
     nsCAutoString s;
 
-    do {
+    while (true) {
         // Ugh, this is a really sloppy way to do this; I copied the
         // implementation from the days when it lived outside the RDF
         // service. Now that it's a member we can be more cleverer.
@@ -1002,24 +1002,19 @@ static PRInt32 kShift = 6;
             id >>= kShift;
         }
 
-        nsIRDFResource* resource;
-        rv = GetResource(s, &resource);
-        if (NS_FAILED(rv)) return rv;
+        ResourceHashEntry *entry = static_cast<ResourceHashEntry*>
+            (PL_DHashTableOperate(&mResources, s.get(), PL_DHASH_ADD));
 
-        // XXX an ugly but effective way to make sure that this
-        // resource is really unique in the world.
-        resource->AddRef();
-        nsrefcnt refcnt = resource->Release();
+        if (entry->mResource)
+            continue;
 
-        if (refcnt == 1) {
-            *aResult = resource;
-            break;
-        }
+        nsRDFResource *resource = new nsRDFResource(s);
+        entry->mResource = resource;
+        entry->mKey = resource->GetInternal();
 
-        NS_RELEASE(resource);
-    } while (1);
-
-    return NS_OK;
+        *aResult = resource;
+        return NS_OK;
+    }
 }