Bug 1229458 - Remove SizeOfIncludingThisMustBeUnshared() from string classes. r=mccr8.

The patch changes all uses of SizeOfIncludingThisMustBeUnshared() to
SizeOfIncludingThisIfUnshared(). This incurs the (tiny) cost of an unnecessary
IsReadonly() check for guaranteed-unshared strings, but avoids the possible
assertion failures that would occur when MustBeUnshared() was used incorrectly
on shared strings, which is an easy mistake to make.
This commit is contained in:
Nicholas Nethercote
2015-12-01 15:36:26 -08:00
parent d837453d60
commit 262f17feb6
10 changed files with 12 additions and 59 deletions

View File

@@ -1001,12 +1001,12 @@ nsTSubstring_CharT::AppendFloat(double aFloat)
}
size_t
nsTSubstring_CharT::SizeOfExcludingThisMustBeUnshared(
nsTSubstring_CharT::SizeOfExcludingThisIfUnshared(
mozilla::MallocSizeOf aMallocSizeOf) const
{
if (mFlags & F_SHARED) {
return nsStringBuffer::FromData(mData)->
SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
SizeOfIncludingThisIfUnshared(aMallocSizeOf);
}
if (mFlags & F_OWNED) {
return aMallocSizeOf(mData);
@@ -1023,27 +1023,11 @@ nsTSubstring_CharT::SizeOfExcludingThisMustBeUnshared(
return 0;
}
size_t
nsTSubstring_CharT::SizeOfExcludingThisIfUnshared(
mozilla::MallocSizeOf aMallocSizeOf) const
{
// This is identical to SizeOfExcludingThisMustBeUnshared except for the
// F_SHARED case.
if (mFlags & F_SHARED) {
return nsStringBuffer::FromData(mData)->
SizeOfIncludingThisIfUnshared(aMallocSizeOf);
}
if (mFlags & F_OWNED) {
return aMallocSizeOf(mData);
}
return 0;
}
size_t
nsTSubstring_CharT::SizeOfExcludingThisEvenIfShared(
mozilla::MallocSizeOf aMallocSizeOf) const
{
// This is identical to SizeOfExcludingThisMustBeUnshared except for the
// This is identical to SizeOfExcludingThisIfUnshared except for the
// F_SHARED case.
if (mFlags & F_SHARED) {
return nsStringBuffer::FromData(mData)->
@@ -1055,14 +1039,6 @@ nsTSubstring_CharT::SizeOfExcludingThisEvenIfShared(
return 0;
}
size_t
nsTSubstring_CharT::SizeOfIncludingThisMustBeUnshared(
mozilla::MallocSizeOf aMallocSizeOf) const
{
return aMallocSizeOf(this) +
SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
}
size_t
nsTSubstring_CharT::SizeOfIncludingThisIfUnshared(
mozilla::MallocSizeOf aMallocSizeOf) const