Bug 1361815 - Do less work in nsTArray's Clear() and destructor. r?froydnj draft
authorAdrian Wielgosik <adrian.wielgosik@gmail.com>
Tue, 17 Oct 2017 19:09:51 +0200
changeset 688168 f1645faece2d246fd0a6de464a523838b728f003
parent 687781 9af785de987dc546c9e792c593cacd7b9b68e8bc
child 688169 0e4ea85b6246754c1122d848378708b0e59ab4b7
push id86676
push userbmo:adrian.wielgosik@gmail.com
push dateSat, 28 Oct 2017 16:37:27 +0000
reviewersfroydnj
bugs1361815
milestone58.0a1
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
@@ -877,18 +877,19 @@ public:
 
   //
   // Finalization method
   //
 
   ~nsTArray_Impl()
   {
     if (!base_type::IsEmpty()) {
-      Clear();
+      ClearAndRetainStorage();
     }
+    // mHdr cleanup will be handled by base destructor
   }
 
   //
   // Initialization methods
   //
 
   nsTArray_Impl() {}
 
@@ -1743,18 +1744,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);