Bug 729403 (part 1) - Add Vector::sizeOf{In,Ex}cludingThis(). r=luke.
--- 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_ */