Bug 682431 (part 1) - Fix up ns{String,CString} SizeOf* functions. r=bz.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 19 Feb 2012 19:16:41 -0800
changeset 87251 c714722a7aad88ec64b96c59adc22de4608bd6d5
parent 87250 969493463a87c7942ac30d75c9548e547f03b976
child 87252 ac02ca06e1273e3c0d4e73589fd6655767d3fc26
push id22103
push userbmo@edmorley.co.uk
push dateTue, 21 Feb 2012 12:01:45 +0000
treeherdermozilla-central@4038ffaa5d82 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs682431
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 682431 (part 1) - Fix up ns{String,CString} SizeOf* functions. r=bz.
xpcom/string/public/nsTSubstring.h
xpcom/string/src/nsTSubstring.cpp
--- a/xpcom/string/public/nsTSubstring.h
+++ b/xpcom/string/public/nsTSubstring.h
@@ -590,37 +590,24 @@ class nsTSubstring_CharT
 #undef XPCOM_STRING_CONSTRUCTOR_OUT_OF_LINE
       nsTSubstring_CharT( char_type *data, size_type length, PRUint32 flags )
         : mData(data),
           mLength(length),
           mFlags(flags) {}
 #endif /* DEBUG || FORCE_BUILD_REFCNT_LOGGING */
 
       size_t SizeOfExcludingThisMustBeUnshared(nsMallocSizeOfFun mallocSizeOf)
-      {
-        NS_ASSERTION(!(mFlags & F_SHARED), "string is shared");
-        return mallocSizeOf(mData);
-      }
-
+        const;
       size_t SizeOfIncludingThisMustBeUnshared(nsMallocSizeOfFun mallocSizeOf)
-      {
-        return mallocSizeOf(this) + SizeOfExcludingThisMustBeUnshared(mallocSizeOf);
-      }
+        const;
 
       size_t SizeOfExcludingThisIfUnshared(nsMallocSizeOfFun mallocSizeOf)
-      {
-        if (mFlags & F_SHARED)
-          return 0;
-        return mallocSizeOf(mData);
-      }
-
+        const;
       size_t SizeOfIncludingThisIfUnshared(nsMallocSizeOfFun mallocSizeOf)
-      {
-        return mallocSizeOf(this) + SizeOfExcludingThisIfUnshared(mallocSizeOf);
-      }
+        const;
 
     protected:
 
       friend class nsTObsoleteAStringThunk_CharT;
       friend class nsTSubstringTuple_CharT;
 
       // XXX GCC 3.4 needs this :-(
       friend class nsTPromiseFlatString_CharT;
--- a/xpcom/string/src/nsTSubstring.cpp
+++ b/xpcom/string/src/nsTSubstring.cpp
@@ -858,8 +858,61 @@ nsTSubstring_CharT::DoAppendFloat( doubl
 {
   char buf[40];
   // Use Modified_cnvtf, which is locale-insensitive, instead of the
   // locale-sensitive PR_snprintf or sprintf(3)
   Modified_cnvtf(buf, sizeof(buf), digits, aFloat);
   AppendASCII(buf);
 }
 
+size_t
+nsTSubstring_CharT::SizeOfExcludingThisMustBeUnshared(
+    nsMallocSizeOfFun mallocSizeOf) const
+{
+  if (mFlags & F_SHARED) {
+    return nsStringBuffer::FromData(mData)->
+             SizeOfIncludingThisMustBeUnshared(mallocSizeOf);
+  } 
+  if (mFlags & F_OWNED) {
+    return mallocSizeOf(mData);
+  }
+
+  // If we reach here, exactly one of the following must be true:
+  // - F_VOIDED is set, and mData points to sEmptyBuffer;
+  // - F_FIXED is set, and mData points to a buffer within a string
+  //   object (e.g. nsAutoString);
+  // - None of F_SHARED, F_OWNED, F_FIXED is set, and mData points to a buffer
+  //   owned by something else.
+  //
+  // In all three cases, we don't measure it.
+  return 0;
+}
+
+size_t
+nsTSubstring_CharT::SizeOfExcludingThisIfUnshared(
+    nsMallocSizeOfFun mallocSizeOf) const
+{
+  // This is identical to SizeOfExcludingThisMustBeUnshared except for the
+  // F_SHARED case.
+  if (mFlags & F_SHARED) {
+    return nsStringBuffer::FromData(mData)->
+             SizeOfIncludingThisIfUnshared(mallocSizeOf);
+  }
+  if (mFlags & F_OWNED) {
+    return mallocSizeOf(mData);
+  }
+  return 0;
+}
+
+size_t
+nsTSubstring_CharT::SizeOfIncludingThisMustBeUnshared(
+    nsMallocSizeOfFun mallocSizeOf) const
+{
+  return mallocSizeOf(this) + SizeOfExcludingThisMustBeUnshared(mallocSizeOf);
+}
+
+size_t
+nsTSubstring_CharT::SizeOfIncludingThisIfUnshared(
+    nsMallocSizeOfFun mallocSizeOf) const
+{
+  return mallocSizeOf(this) + SizeOfExcludingThisIfUnshared(mallocSizeOf);
+}
+