xultemplates-gcobjects
author Benjamin Smedberg <benjamin@smedbergs.us>
Sat, 26 Jul 2008 22:49:39 -0400
changeset 167 a4da40849f5436e629c5732f4368c6c48189637f
parent 164 fa6388d0a0da8b02a6de7c99bb09ca58d2dd2013
permissions -rw-r--r--
State as of now

* * *

diff --git a/content/xul/templates/src/nsRDFConInstanceTestNode.h b/content/xul/templates/src/nsRDFConInstanceTestNode.h
--- a/content/xul/templates/src/nsRDFConInstanceTestNode.h
+++ b/content/xul/templates/src/nsRDFConInstanceTestNode.h
@@ -77,12 +77,6 @@ public:
 
 
     class Element : public MemoryElement {
-    protected:
-        // Hide so that only Create() and Destroy() can be used to
-        // allocate and deallocate from the heap
-        static void* operator new(size_t) CPP_THROW_NEW { return 0; }
-        static void operator delete(void*, size_t) {}
-
     public:
         Element(nsIRDFResource* aContainer,
                 Test aContainerTest,
@@ -97,12 +91,7 @@ public:
         static Element*
         Create(nsIRDFResource* aContainer,
                Test aContainerTest, Test aEmptyTest) {
-            void* place = MemoryElement::gPool.Alloc(sizeof(Element));
-            return place ? ::new (place) Element(aContainer, aContainerTest, aEmptyTest) : nsnull; }
-
-        void Destroy() {
-            this->~Element();
-            MemoryElement::gPool.Free(this, sizeof(Element));
+            return new Element(aContainer, aContainerTest, aEmptyTest);
         }
 
         virtual const char* Type() const {
diff --git a/content/xul/templates/src/nsRDFConMemberTestNode.h b/content/xul/templates/src/nsRDFConMemberTestNode.h
--- a/content/xul/templates/src/nsRDFConMemberTestNode.h
+++ b/content/xul/templates/src/nsRDFConMemberTestNode.h
@@ -72,12 +72,6 @@ public:
             nsIRDFNode* aTarget) const;
 
     class Element : public MemoryElement {
-    protected:
-        // Hide so that only Create() and Destroy() can be used to
-        // allocate and deallocate from the heap
-        static void* operator new(size_t) CPP_THROW_NEW { return 0; }
-        static void operator delete(void*, size_t) {}
-
     public:
         Element(nsIRDFResource* aContainer,
                 nsIRDFNode* aMember)
@@ -89,12 +83,7 @@ public:
 
         static Element*
         Create(nsIRDFResource* aContainer, nsIRDFNode* aMember) {
-            void* place = MemoryElement::gPool.Alloc(sizeof(Element));
-            return place ? ::new (place) Element(aContainer, aMember) : nsnull; }
-
-        void Destroy() {
-            this->~Element();
-            MemoryElement::gPool.Free(this, sizeof(Element));
+            return new Element(aContainer, aMember);
         }
 
         virtual const char* Type() const {
diff --git a/content/xul/templates/src/nsRDFPropertyTestNode.h b/content/xul/templates/src/nsRDFPropertyTestNode.h
--- a/content/xul/templates/src/nsRDFPropertyTestNode.h
+++ b/content/xul/templates/src/nsRDFPropertyTestNode.h
@@ -91,12 +91,6 @@ public:
 
 
     class Element : public MemoryElement {
-    protected:
-        // Hide so that only Create() and Destroy() can be used to
-        // allocate and deallocate from the heap
-        static void* operator new(size_t) CPP_THROW_NEW { return 0; }
-        static void operator delete(void*, size_t) {}
-
     public:
         Element(nsIRDFResource* aSource,
                 nsIRDFResource* aProperty,
@@ -112,12 +106,7 @@ public:
         Create(nsIRDFResource* aSource,
                nsIRDFResource* aProperty,
                nsIRDFNode* aTarget) {
-            void* place = MemoryElement::gPool.Alloc(sizeof(Element));
-            return place ? ::new (place) Element(aSource, aProperty, aTarget) : nsnull; }
-
-        void Destroy() {
-            this->~Element();
-            MemoryElement::gPool.Free(this, sizeof(Element));
+            return new Element(aSource, aProperty, aTarget);
         }
 
         virtual const char* Type() const {
diff --git a/content/xul/templates/src/nsRuleNetwork.cpp b/content/xul/templates/src/nsRuleNetwork.cpp
--- a/content/xul/templates/src/nsRuleNetwork.cpp
+++ b/content/xul/templates/src/nsRuleNetwork.cpp
@@ -73,29 +73,6 @@ extern PRLogModuleInfo* gXULTemplateLog;
 #include "nsRDFConMemberTestNode.h"
 #include "nsRDFPropertyTestNode.h"
 
-PRBool MemoryElement::gPoolInited;
-nsFixedSizeAllocator MemoryElement::gPool;
-
-// static
-PRBool
-MemoryElement::Init()
-{
-    if (!gPoolInited) {
-        const size_t bucketsizes[] = {
-            sizeof (nsRDFConMemberTestNode::Element),
-            sizeof (nsRDFPropertyTestNode::Element)
-        };
-
-        if (NS_FAILED(gPool.Init("MemoryElement", bucketsizes,
-                                 NS_ARRAY_LENGTH(bucketsizes), 256)))
-            return PR_FALSE;
-
-        gPoolInited = PR_TRUE;
-    }
-
-    return PR_TRUE;
-}
-
 //----------------------------------------------------------------------
 //
 // nsRuleNetwork
@@ -104,22 +81,11 @@ nsresult
 nsresult
 MemoryElementSet::Add(MemoryElement* aElement)
 {
-    for (ConstIterator element = First(); element != Last(); ++element) {
-        if (*element == *aElement) {
-            // We've already got this element covered. Since Add()
-            // assumes ownership, and we aren't going to need this,
-            // just nuke it.
-            aElement->Destroy();
-            return NS_OK;
-        }
-    }
-
     List* list = new List;
     if (! list)
         return NS_ERROR_OUT_OF_MEMORY;
 
     list->mElement = aElement;
-    list->mRefCnt  = 1;
     list->mNext    = mElements;
 
     mElements = list;
@@ -131,20 +97,18 @@ MemoryElementSet::Add(MemoryElement* aEl
 //----------------------------------------------------------------------
 
 nsresult
-nsAssignmentSet::Add(const nsAssignment& aAssignment)
+nsAssignmentSet::Add(nsIAtom* aVariable, nsIRDFNode* aValue)
 {
-    NS_PRECONDITION(! HasAssignmentFor(aAssignment.mVariable), "variable already bound");
+    NS_PRECONDITION(! HasAssignmentFor(aVariable), "variable already bound");
 
     // XXXndeakin should this just silently fail?
-    if (HasAssignmentFor(aAssignment.mVariable))
+    if (HasAssignmentFor(aVariable))
         return NS_ERROR_UNEXPECTED;
 
-    List* list = new List;
+    List* list = new List(aVariable, aValue);
     if (! list)
         return NS_ERROR_OUT_OF_MEMORY;
 
-    list->mAssignment = aAssignment;
-    list->mRefCnt     = 1;
     list->mNext       = mAssignments;
 
     mAssignments = list;
diff --git a/content/xul/templates/src/nsRuleNetwork.h b/content/xul/templates/src/nsRuleNetwork.h
--- a/content/xul/templates/src/nsRuleNetwork.h
+++ b/content/xul/templates/src/nsRuleNetwork.h
@@ -93,12 +93,6 @@ protected:
     virtual ~MemoryElement() { MOZ_COUNT_DTOR(MemoryElement); }
 public:
 
-    static PRBool Init();
-
-    static PRBool gPoolInited;
-    static nsFixedSizeAllocator gPool;
-
-    virtual void Destroy() = 0;
     virtual const char* Type() const = 0;
     virtual PLHashNumber Hash() const = 0;
     virtual PRBool Equals(const MemoryElement& aElement) const = 0;
@@ -129,18 +123,9 @@ protected:
 
         ~List() {
             MOZ_COUNT_DTOR(MemoryElementSet::List);
-            mElement->Destroy();
             NS_IF_RELEASE(mNext); }
 
-        PRInt32 AddRef() { return ++mRefCnt; }
-
-        PRInt32 Release() {
-            PRInt32 refcnt = --mRefCnt;
-            if (refcnt == 0) delete this;
-            return refcnt; }
-
         MemoryElement* mElement;
-        PRInt32        mRefCnt;
         List*          mNext;
     };
 
@@ -277,21 +262,10 @@ protected:
 protected:
     class List {
     public:
-        List() { MOZ_COUNT_CTOR(nsAssignmentSet::List); }
-
-        ~List() {
-            MOZ_COUNT_DTOR(nsAssignmentSet::List);
-            NS_IF_RELEASE(mNext); }
-
-        PRInt32 AddRef() { return ++mRefCnt; }
-
-        PRInt32 Release() {
-            PRInt32 refcnt = --mRefCnt;
-            if (refcnt == 0) delete this;
-            return refcnt; }
+        List(nsIAtom* atom, nsIRDFNode* node) 
+            : mAssignment(atom, node), mNext(nsnull) { }
 
         nsAssignment mAssignment;
-        PRInt32 mRefCnt;
         List*   mNext;
     };
 
@@ -376,7 +350,7 @@ public:
      * @return NS_OK if all is well, NS_ERROR_OUT_OF_MEMORY if memory
      *   could not be allocated for the addition.
      */
-    nsresult Add(const nsAssignment& aElement);
+    nsresult Add(nsIAtom* aVariable, nsIRDFNode* aValue);
 
     /**
      * Determine if the assignment set contains the specified variable
@@ -484,7 +458,7 @@ public:
      *   is not enough memory to perform the operation
      */
     nsresult AddAssignment(nsIAtom* aVariable, nsIRDFNode* aValue) {
-        mAssignments.Add(nsAssignment(aVariable, aValue));
+        mAssignments.Add(aVariable, aValue);
         return NS_OK; }
 
     /**
diff --git a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
--- a/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
+++ b/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp
@@ -150,7 +150,7 @@ nsXULTemplateQueryProcessorRDF::InitGlob
                              &kRDF_type);
     }
 
-    return MemoryElement::Init() ? NS_OK : NS_ERROR_FAILURE;
+    return NS_OK;
 }
 
 //----------------------------------------------------------------------