Bug 671299 (part 2) - Add nsStringBuffer::SizeOfIncludingThisMustBeUnshared. r=bz.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 02 Jan 2012 18:19:12 -0800
changeset 88811 81de95739be64201cd1d71f6584f13d13b1f8635
parent 88810 1a8240eccb8f6b56b6cf477c094e89b7e59d2374
child 88812 b2f1b368e2f25a5791a4b146f0ac709ca9f029fe
push id783
push userlsblakk@mozilla.com
push dateTue, 24 Apr 2012 17:33:42 +0000
treeherdermozilla-beta@11faed19f136 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs671299
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 671299 (part 2) - Add nsStringBuffer::SizeOfIncludingThisMustBeUnshared. r=bz.
xpcom/string/public/nsStringBuffer.h
xpcom/string/src/nsSubstring.cpp
--- a/xpcom/string/public/nsStringBuffer.h
+++ b/xpcom/string/public/nsStringBuffer.h
@@ -166,14 +166,20 @@ class nsStringBuffer
        *       (2-byte units for wide strings).
        */
       void ToString(PRUint32 len, nsAString &str,
                            bool aMoveOwnership = false);
       void ToString(PRUint32 len, nsACString &str,
                            bool aMoveOwnership = false);
 
       /**
+       * This measures the size.  It should only be used if the StringBuffer is
+       * unshared.  This is checked.
+       */
+      size_t SizeOfIncludingThisMustBeUnshared(nsMallocSizeOfFun aMallocSizeOf) const;
+
+      /**
        * This measures the size only if the StringBuffer is unshared.
        */
       size_t SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun aMallocSizeOf) const;
   };
 
 #endif /* !defined(nsStringBuffer_h__ */
--- a/xpcom/string/src/nsSubstring.cpp
+++ b/xpcom/string/src/nsSubstring.cpp
@@ -303,21 +303,29 @@ nsStringBuffer::ToString(PRUint32 len, n
 
     if (!aMoveOwnership) {
       AddRef();
     }
     accessor->set(data, len, flags);
   }
 
 size_t
+nsStringBuffer::SizeOfIncludingThisMustBeUnshared(nsMallocSizeOfFun aMallocSizeOf) const
+  {
+    NS_ASSERTION(!IsReadonly(),
+                 "shared StringBuffer in SizeOfIncludingThisMustBeUnshared");
+    return aMallocSizeOf(this);
+  }
+
+size_t
 nsStringBuffer::SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun aMallocSizeOf) const
   {
     if (!IsReadonly())
       {
-        return aMallocSizeOf(this);
+        return SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
       }
     return 0;
   }
 
 // ---------------------------------------------------------------------------
 
 
   // define nsSubstring