diff --git a/xpcom/string/public/nsStringBuffer.h b/xpcom/string/public/nsStringBuffer.h index 83db7804c76..229ee050325 100644 --- a/xpcom/string/public/nsStringBuffer.h +++ b/xpcom/string/public/nsStringBuffer.h @@ -169,6 +169,11 @@ class nsStringBuffer 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__ */ diff --git a/xpcom/string/src/nsSubstring.cpp b/xpcom/string/src/nsSubstring.cpp index d3842e2174a..65250834cd3 100644 --- a/xpcom/string/src/nsSubstring.cpp +++ b/xpcom/string/src/nsSubstring.cpp @@ -307,6 +307,16 @@ nsStringBuffer::ToString(PRUint32 len, nsACString &str, accessor->set(data, len, flags); } +size_t +nsStringBuffer::SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun aMallocSizeOf) const + { + if (!IsReadonly()) + { + return aMallocSizeOf(this, sizeof(nsStringBuffer) + mStorageSize); + } + return 0; + } + // ---------------------------------------------------------------------------