Bug 729403 (part 1) - Add Vector::sizeOf{In,Ex}cludingThis(). r=luke.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 21 Feb 2012 20:58:40 -0800
changeset 90684 da193f5b526bf3cb2a9f2da672b72eea2de03d9d
parent 90683 7af360ee95fec6da9bf35990310bbdec905469aa
child 90685 a7255af10a2a07d90ecc5739f0891381a2b9da8d
push idunknown
push userunknown
push dateunknown
reviewersluke
bugs729403
milestone13.0a1
Bug 729403 (part 1) - Add Vector::sizeOf{In,Ex}cludingThis(). r=luke.
js/public/Vector.h
--- a/js/public/Vector.h
+++ b/js/public/Vector.h
@@ -494,16 +494,27 @@ class Vector : private AllocPolicy
      */
     bool insert(T *p, const T &val);
 
     /*
      * Removes the element |t|, which must fall in the bounds [begin, end),
      * shifting existing elements from |t + 1| onward one position lower.
      */
     void erase(T *t);
+
+    /*
+     * Measure the size of the Vector's heap-allocated storage.
+     */
+    size_t sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf) const;
+
+    /* 
+     * Like sizeOfExcludingThis, but also measures the size of the Vector
+     * object (which must be heap-allocated) itself.
+     */
+    size_t sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf) const;
 };
 
 /* This does the re-entrancy check plus several other sanity checks. */
 #define REENTRANCY_GUARD_ET_AL \
     ReentrancyGuard g(*this); \
     JS_ASSERT_IF(usingInlineStorage(), mCapacity == sInlineCapacity); \
     JS_ASSERT(reserved() <= mCapacity); \
     JS_ASSERT(mLength <= reserved()); \
@@ -991,15 +1002,29 @@ Vector<T,N,AP>::replaceRawBuffer(T *p, s
         mLength = length;
         mCapacity = length;
     }
 #ifdef DEBUG
     mReserved = length;
 #endif
 }
 
+template <class T, size_t N, class AP>
+inline size_t
+Vector<T,N,AP>::sizeOfExcludingThis(JSMallocSizeOfFun mallocSizeOf) const
+{
+    return usingInlineStorage() ? 0 : mallocSizeOf(beginNoCheck());
+}
+
+template <class T, size_t N, class AP>
+inline size_t
+Vector<T,N,AP>::sizeOfIncludingThis(JSMallocSizeOfFun mallocSizeOf) const
+{
+    return mallocSizeOf(this) + sizeOfExcludingThis(mallocSizeOf);
+}
+
 }  /* namespace js */
 
 #ifdef _MSC_VER
 #pragma warning(pop)
 #endif
 
 #endif /* jsvector_h_ */