Bug 674284: Add nsTArray::SizeOf. r=bsmedberg
authorKyle Huey <khuey@kylehuey.com>
Mon, 01 Aug 2011 14:37:00 -0400
changeset 73677 bd93ca20e1fd1cf2a98cabe1be1897e83a099f15
parent 73676 fa54a739294bf6ae1df98ec15a1308d77ecafc2d
child 73678 b1013d7d7cd8977db811b7f3a0ef374ca3c094fc
push id20903
push userkhuey@kylehuey.com
push dateTue, 02 Aug 2011 15:33:56 +0000
treeherdermozilla-central@b1013d7d7cd8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs674284
milestone8.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 674284: Add nsTArray::SizeOf. r=bsmedberg
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -425,16 +425,22 @@ public:
   }
 
   template<typename Allocator>
   nsTArray& operator=(const nsTArray<E, Allocator>& other) {
     ReplaceElementsAt(0, Length(), other.Elements(), other.Length());
     return *this;
   }
 
+  // @return The amount of memory taken used by this nsTArray, not including
+  // sizeof(this)
+  size_t SizeOf() const {
+    return this->Capacity() * sizeof(elem_type) + sizeof(*this->Hdr());
+  }
+
   //
   // Accessor methods
   //
 
   // This method provides direct access to the array elements.
   // @return A pointer to the first element of the array.  If the array is
   // empty, then this pointer must not be dereferenced.
   elem_type* Elements() {