Bug 1361815 - Do less work in nsTArray's Clear() and destructor. r?froydnj
MozReview-Commit-ID: DnkE7LFxkF3
--- 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() {}
@@ -1729,18 +1730,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);