Bug 712835 (part 1 of 3) - Add nsStringBuffer::SizeOfIncludingThisIfUnshared(). r=khuey.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 22 Dec 2011 16:57:30 -0800
changeset 84647 365161a949b534aa978c0e836242d91adcece440
parent 84646 9c78b487233347155c1dd02d8a7f251a24db4aae
child 84648 4b655c46d0713d8edb1e9946da037698a5572cbb
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs712835
milestone12.0a1
Bug 712835 (part 1 of 3) - Add nsStringBuffer::SizeOfIncludingThisIfUnshared(). r=khuey.
xpcom/string/public/nsStringBuffer.h
xpcom/string/src/nsSubstring.cpp
--- a/xpcom/string/public/nsStringBuffer.h
+++ b/xpcom/string/public/nsStringBuffer.h
@@ -164,11 +164,16 @@ class nsStringBuffer
        * NOTE: storage size is measured in bytes even for wide strings;
        *       however, string length is always measured in storage units
        *       (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 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
@@ -302,16 +302,26 @@ nsStringBuffer::ToString(PRUint32 len, n
     flags = (flags & 0xFFFF0000) | nsCSubstring::F_SHARED | nsCSubstring::F_TERMINATED;
 
     if (!aMoveOwnership) {
       AddRef();
     }
     accessor->set(data, len, flags);
   }
 
+size_t
+nsStringBuffer::SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun aMallocSizeOf) const
+  {
+    if (!IsReadonly())
+      {
+        return aMallocSizeOf(this, sizeof(nsStringBuffer) + mStorageSize);
+      }
+    return 0;
+  }
+
 // ---------------------------------------------------------------------------
 
 
   // define nsSubstring
 #include "string-template-def-unichar.h"
 #include "nsTSubstring.cpp"
 #include "string-template-undef.h"