Bug 671299 (part 2) - Add nsStringBuffer::SizeOfIncludingThisMustBeUnshared. r=bz.

This commit is contained in:
Nicholas Nethercote
2012-01-02 18:19:12 -08:00
parent adee4b2e06
commit cf5bec0e68
2 changed files with 15 additions and 1 deletions

View File

@@ -170,6 +170,12 @@ class nsStringBuffer
void ToString(PRUint32 len, nsACString &str, void ToString(PRUint32 len, nsACString &str,
bool aMoveOwnership = false); 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. * This measures the size only if the StringBuffer is unshared.
*/ */

View File

@@ -307,12 +307,20 @@ nsStringBuffer::ToString(PRUint32 len, nsACString &str,
accessor->set(data, len, flags); accessor->set(data, len, flags);
} }
size_t
nsStringBuffer::SizeOfIncludingThisMustBeUnshared(nsMallocSizeOfFun aMallocSizeOf) const
{
NS_ASSERTION(!IsReadonly(),
"shared StringBuffer in SizeOfIncludingThisMustBeUnshared");
return aMallocSizeOf(this);
}
size_t size_t
nsStringBuffer::SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun aMallocSizeOf) const nsStringBuffer::SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun aMallocSizeOf) const
{ {
if (!IsReadonly()) if (!IsReadonly())
{ {
return aMallocSizeOf(this); return SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
} }
return 0; return 0;
} }