Bug 1322843 part 1 - Add Reverse method to nsTArray. r=froydnj
MozReview-Commit-ID: 8VNEFzHn4dC
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -2012,16 +2012,26 @@ public:
NS_QuickSort(Elements(), Length(), sizeof(elem_type),
Compare<Comparator>, const_cast<Comparator*>(&aComp));
}
// A variation on the Sort method defined above that assumes that
// 'operator<' is defined for elem_type.
void Sort() { Sort(nsDefaultComparator<elem_type, elem_type>()); }
+ // This method reverses the array in place.
+ void Reverse()
+ {
+ elem_type* elements = Elements();
+ const size_type len = Length();
+ for (index_type i = 0, iend = len / 2; i < iend; ++i) {
+ mozilla::Swap(elements[i], elements[len - i - 1]);
+ }
+ }
+
protected:
using base_type::Hdr;
using base_type::ShrinkCapacity;
// This method invokes elem_type's destructor on a range of elements.
// @param aStart The index of the first element to destroy.
// @param aCount The number of elements to destroy.
void DestructRange(index_type aStart, size_type aCount)