Bug 1374033 - Remove double bounds checking from the next accessors of the iterator classes of nsTObserverArray; r=froydnj
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 18 Jun 2017 02:43:55 -0400
changeset 364825 3b573b3cb04745ffe2898f53ef7b9a4a9f956598
parent 364824 bde143a9c8b2b596e10b15a767becf040802037a
child 364826 e1d521fcbb0d7c76e4fe1c042f0c07f285ab96dd
push id32055
push usercbook@mozilla.com
push dateTue, 20 Jun 2017 09:26:54 +0000
treeherdermozilla-central@7a6baa6cca32 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1374033
milestone56.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 1374033 - Remove double bounds checking from the next accessors of the iterator classes of nsTObserverArray; r=froydnj
xpcom/ds/nsTObserverArray.h
--- a/xpcom/ds/nsTObserverArray.h
+++ b/xpcom/ds/nsTObserverArray.h
@@ -88,16 +88,28 @@ public:
   //
 
   // @return The number of elements in the array.
   size_type Length() const { return mArray.Length(); }
 
   // @return True if the array is empty or false otherwise.
   bool IsEmpty() const { return mArray.IsEmpty(); }
 
+  // This method provides direct, readonly access to the array elements.
+  // @return A pointer to the first element of the array.  If the array is
+  // empty, then this pointer must not be dereferenced.
+  const elem_type* Elements() const
+  {
+    return mArray.Elements();
+  }
+  elem_type* Elements()
+  {
+    return mArray.Elements();
+  }
+
   // This method provides direct access to an element of the array. The given
   // index must be within the array bounds. If the underlying array may change
   // during iteration, use an iterator instead of this function.
   // @param aIndex The index of an element in the array.
   // @return A reference to the i'th element of the array.
   elem_type& ElementAt(index_type aIndex)
   {
     return mArray.ElementAt(aIndex);
@@ -356,17 +368,17 @@ public:
     }
 
     // Returns the next element and steps one step. This must
     // be preceded by a call to HasMore().
     // @return The next observer.
     elem_type& GetNext()
     {
       NS_ASSERTION(HasMore(), "iterating beyond end of array");
-      return base_type::mArray.ElementAt(base_type::mPosition++);
+      return base_type::mArray.Elements()[base_type::mPosition++];
     }
   };
 
   // EndLimitedIterator works like ForwardIterator, but will not iterate new
   // observers appended to the array after the iterator was created.
   class EndLimitedIterator : protected ForwardIterator
   {
   public:
@@ -385,17 +397,17 @@ public:
     bool HasMore() const { return *this < mEnd; }
 
     // Returns the next element and steps one step. This must
     // be preceded by a call to HasMore().
     // @return The next observer.
     elem_type& GetNext()
     {
       NS_ASSERTION(HasMore(), "iterating beyond end of array");
-      return base_type::mArray.ElementAt(base_type::mPosition++);
+      return base_type::mArray.Elements()[base_type::mPosition++];
     }
 
   private:
     ForwardIterator mEnd;
   };
 
   // Iterates the array backward from end to start. mPosition points
   // to the element that was returned last.
@@ -421,17 +433,17 @@ public:
     bool HasMore() const { return base_type::mPosition > 0; }
 
     // Returns the next element and steps one step. This must
     // be preceded by a call to HasMore().
     // @return The next observer.
     elem_type& GetNext()
     {
       NS_ASSERTION(HasMore(), "iterating beyond start of array");
-      return base_type::mArray.ElementAt(--base_type::mPosition);
+      return base_type::mArray.Elements()[--base_type::mPosition];
     }
 
     // Removes the element at the current iterator position.
     // (the last element returned from |GetNext()|)
     // This will not affect the next call to |GetNext()|
     void Remove()
     {
       return base_type::mArray.RemoveElementAt(base_type::mPosition);