Bug 1361815 - Do less work in nsTArray's Clear() and destructor. r=froydnj
authorAdrian Wielgosik <adrian.wielgosik@gmail.com>
Tue, 17 Oct 2017 19:09:51 +0200
changeset 450816 dd2b9748cbb66622643d5a15a2efe6edd8707ff1
parent 450815 95e2f1556c172a88792415f3a5637f9cbcac2358
child 450817 e013d41a44e7b9178d155571d18e329128191499
push id8543
push userryanvm@gmail.com
push dateTue, 16 Jan 2018 14:33:22 +0000
treeherdermozilla-beta@a6525ed16a32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1361815
milestone59.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 1361815 - Do less work in nsTArray's Clear() and destructor. r=froydnj MozReview-Commit-ID: DnkE7LFxkF3
xpcom/ds/nsTArray.h
--- a/xpcom/ds/nsTArray.h
+++ b/xpcom/ds/nsTArray.h
@@ -845,18 +845,19 @@ public:
 
   //
   // Finalization method
   //
 
   ~nsTArray_Impl()
   {
     if (!base_type::IsEmpty()) {
-      Clear();
+      ClearAndRetainStorage();
     }
+    // mHdr cleanup will be handled by base destructor
   }
 
   //
   // Initialization methods
   //
 
   nsTArray_Impl() {}
 
@@ -1711,18 +1712,20 @@ public:
   // This method removes a range of elements from this array.
   // @param aStart The starting index of the elements to remove.
   // @param aCount The number of elements to remove.
   void RemoveElementsAt(index_type aStart, size_type aCount);
 
   // A variation on the RemoveElementsAt method defined above.
   void RemoveElementAt(index_type aIndex) { RemoveElementsAt(aIndex, 1); }
 
-  // A variation on the RemoveElementsAt method defined above.
-  void Clear() { RemoveElementsAt(0, Length()); }
+  void Clear() {
+    ClearAndRetainStorage();
+    Compact();
+  }
 
   // This method removes elements based on the return value of the
   // callback function aPredicate. If the function returns true for
   // an element, the element is removed. aPredicate will be called
   // for each element in order. It is not safe to access the array
   // inside aPredicate.
   template<typename Predicate>
   void RemoveElementsBy(Predicate aPredicate);