Bug 739129 - Add LastElement and SafeLastElement functions to nsTArray. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Tue, 27 Mar 2012 09:48:25 +1100
changeset 93679 c7cce5198d83ee777fb6d132bef6803e614e9018
parent 93678 022b7fc56c7b9e5a23c46f8e114c1b51ceb45d45
child 93680 6b3d2762c0fb8b7176d8efbe2bdea5b1a4d8e774
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs739129
milestone14.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 739129 - Add LastElement and SafeLastElement functions to nsTArray. r=dbaron
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -591,16 +591,36 @@ public:
     return ElementAt(i);
   }
 
   // Shorthand for ElementAt(i)
   const elem_type& operator[](index_type i) const {
     return ElementAt(i);
   }
 
+  // Shorthand for ElementAt(length - 1)
+  elem_type& LastElement() {
+    return ElementAt(Length() - 1);
+  }
+
+  // Shorthand for ElementAt(length - 1)
+  const elem_type& LastElement() const {
+    return ElementAt(Length() - 1);
+  }
+
+  // Shorthand for SafeElementAt(length - 1, def)
+  elem_type& SafeLastElement(elem_type& def) {
+    return SafeElementAt(Length() - 1, def);
+  }
+
+  // Shorthand for SafeElementAt(length - 1, def)
+  const elem_type& SafeLastElement(const elem_type& def) const {
+    return SafeElementAt(Length() - 1, def);
+  }
+
   //
   // Search methods
   //
 
   // This method searches for the first element in this array that is equal
   // to the given element.
   // @param item   The item to search for.
   // @param comp   The Comparator used to determine element equality.