Bug 712835 (part 1 of 3) - Add nsStringBuffer::SizeOfIncludingThisIfUnshared(). r=khuey.
--- 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"