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

diff --git a/content/base/src/nsAttrAndChildArray.cpp b/content/base/src/nsAttrAndChildArray.cpp
--- a/content/base/src/nsAttrAndChildArray.cpp
+++ b/content/base/src/nsAttrAndChildArray.cpp
@@ -118,22 +118,6 @@ GetIndexFromCache(const nsAttrAndChildAr
 
 #define NS_IMPL_EXTRA_SIZE \
   ((sizeof(Impl) - sizeof(mImpl->mBuffer)) / sizeof(void*))
-
-nsAttrAndChildArray::nsAttrAndChildArray()
-  : mImpl(nsnull)
-{
-}
-
-nsAttrAndChildArray::~nsAttrAndChildArray()
-{
-  if (!mImpl) {
-    return;
-  }
-
-  Clear();
-
-  PR_Free(mImpl);
-}
 
 nsIContent*
 nsAttrAndChildArray::GetSafeChildAt(PRUint32 aPos) const
@@ -755,16 +739,17 @@ nsAttrAndChildArray::GrowBy(PRUint32 aGr
     size = PR_BIT(PR_CeilingLog2(minSize));
   }
 
-  Impl* newImpl = static_cast<Impl*>
-                             (mImpl ? PR_Realloc(mImpl, size * sizeof(void*)) :
-              PR_Malloc(size * sizeof(void*)));
+  Impl* newImpl = new(size * sizeof(void*)) Impl;
   NS_ENSURE_TRUE(newImpl, PR_FALSE);
 
   Impl* oldImpl = mImpl;
   mImpl = newImpl;
-
   // Set initial counts if we didn't have a buffer before
-  if (!oldImpl) {
+  if (oldImpl) {
+    memcpy(mImpl, oldImpl,
+           (NS_IMPL_EXTRA_SIZE + oldImpl->mBufferSize) * sizeof(void*));
+  }
+  else {
     mImpl->mMappedAttrs = nsnull;
     SetAttrSlotAndChildCount(0, 0);
   }
diff --git a/content/base/src/nsAttrAndChildArray.h b/content/base/src/nsAttrAndChildArray.h
--- a/content/base/src/nsAttrAndChildArray.h
+++ b/content/base/src/nsAttrAndChildArray.h
@@ -75,8 +75,8 @@ class nsAttrAndChildArray
 class nsAttrAndChildArray
 {
 public:
-  nsAttrAndChildArray();
-  ~nsAttrAndChildArray();
+  nsAttrAndChildArray() : mImpl(nsnull) { }
+  ~nsAttrAndChildArray() { }
 
   PRUint32 ChildCount() const
   {
@@ -179,11 +179,18 @@ private:
     nsAttrValue mValue;
   };
 
-  struct Impl {
+  struct Impl : public XPCOMGCObject
+  {
     PRUint32 mAttrAndChildCount;
     PRUint32 mBufferSize;
     nsMappedAttributes* mMappedAttrs;
     void* mBuffer[1];
+
+    // Ignore "size" and operate only on realSize
+    static void* operator new(size_t size, size_t realSize)
+    {
+      return XPCOMGCObject::operator new(realSize);
+    }
   };
 
   Impl* mImpl;
diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -72,8 +72,6 @@ nsGenericDOMDataNode::nsGenericDOMDataNo
 
 nsGenericDOMDataNode::~nsGenericDOMDataNode()
 {
-  NS_PRECONDITION(!IsInDoc(),
-                  "Please remove this from the document properly");
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericDOMDataNode)
diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -1094,8 +1094,6 @@ nsGenericElement::nsGenericElement(nsINo
 
 nsGenericElement::~nsGenericElement()
 {
-  NS_PRECONDITION(!IsInDoc(),
-                  "Please remove this from the document properly");
 }
 
 NS_IMETHODIMP