Bug 1175485 part 1 - Allow inner iterator of ReverseIterator deref to any type, and change IntegerIterator, EnumeratedRange, and nsFrameList::Iterator to return value type instead of a reference. r=roc,waldo
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 02 Jul 2015 13:31:07 +1000
changeset 251091 13b68b2357f9505e688fabb4cbfa81da5d63c976
parent 251090 12b85be1c5a0c6ba0ea3af68f2df0a1139a2cee6
child 251092 addb5b05538307ed1d2c75497ed469e393e6791d
push id28980
push usercbook@mozilla.com
push dateThu, 02 Jul 2015 13:44:32 +0000
treeherdermozilla-central@f1b3144fed94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, waldo
bugs1175485
milestone42.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 1175485 part 1 - Allow inner iterator of ReverseIterator deref to any type, and change IntegerIterator, EnumeratedRange, and nsFrameList::Iterator to return value type instead of a reference. r=roc,waldo
layout/generic/nsFrameList.h
mfbt/EnumeratedRange.h
mfbt/IntegerRange.h
mfbt/ReverseIterator.h
--- a/layout/generic/nsFrameList.h
+++ b/layout/generic/nsFrameList.h
@@ -446,32 +446,32 @@ public:
 
   protected:
     nsIFrame* mPrev;
   };
 
   class Iterator
   {
   public:
-    typedef nsIFrame* const ValueType;
+    typedef nsIFrame* ValueType;
     // Though we don't support +/- a integer currently,
     // iterators have to have a DifferenceType.
     typedef ptrdiff_t DifferenceType;
 
     Iterator(const nsFrameList& aList, nsIFrame* aCurrent)
       : mList(aList)
       , mCurrent(aCurrent)
     {}
 
     Iterator(const Iterator& aOther)
       : mList(aOther.mList)
       , mCurrent(aOther.mCurrent)
     {}
 
-    ValueType& operator*() const { return mCurrent; }
+    nsIFrame* operator*() const { return mCurrent; }
 
     // The operators need to know about nsIFrame, hence the
     // implementations are in nsIFrame.h
     Iterator& operator++();
     Iterator& operator--();
 
     Iterator operator++(int) { auto ret = *this; ++*this; return ret; }
     Iterator operator--(int) { auto ret = *this; --*this; return ret; }
--- a/mfbt/EnumeratedRange.h
+++ b/mfbt/EnumeratedRange.h
@@ -15,41 +15,39 @@
  * Note that the enum values should be contiguous in the iterated range;
  * unfortunately there exists no way for EnumeratedRange to enforce this
  * either dynamically or at compile time.
  */
 
 #ifndef mozilla_EnumeratedRange_h
 #define mozilla_EnumeratedRange_h
 
-#include "mozilla/IntegerRange.h"
 #include "mozilla/IntegerTypeTraits.h"
+#include "mozilla/ReverseIterator.h"
 
 namespace mozilla {
 
 namespace detail {
 
 template<typename IntTypeT, typename EnumTypeT>
 class EnumeratedIterator
 {
 public:
-  typedef const EnumTypeT ValueType;
+  typedef EnumTypeT ValueType;
   typedef typename MakeSigned<IntTypeT>::Type DifferenceType;
 
   template<typename EnumType>
   explicit EnumeratedIterator(EnumType aCurrent)
     : mCurrent(aCurrent) { }
 
   template<typename IntType, typename EnumType>
   EnumeratedIterator(const EnumeratedIterator<IntType, EnumType>& aOther)
     : mCurrent(aOther.mCurrent) { }
 
-  // Since operator* is required to return a reference, we return
-  // a reference to our member here.
-  const EnumTypeT& operator*() const { return mCurrent; }
+  EnumTypeT operator*() const { return mCurrent; }
 
   /* Increment and decrement operators */
 
   EnumeratedIterator& operator++()
   {
     mCurrent = EnumTypeT(IntTypeT(mCurrent) + IntTypeT(1));
     return *this;
   }
--- a/mfbt/IntegerRange.h
+++ b/mfbt/IntegerRange.h
@@ -16,30 +16,28 @@
 namespace mozilla {
 
 namespace detail {
 
 template<typename IntTypeT>
 class IntegerIterator
 {
 public:
-  typedef const IntTypeT ValueType;
+  typedef IntTypeT ValueType;
   typedef typename MakeSigned<IntTypeT>::Type DifferenceType;
 
   template<typename IntType>
   explicit IntegerIterator(IntType aCurrent)
     : mCurrent(aCurrent) { }
 
   template<typename IntType>
   IntegerIterator(const IntegerIterator<IntType>& aOther)
     : mCurrent(aOther.mCurrent) { }
 
-  // Since operator* is required to return a reference, we return
-  // a reference to our member here.
-  const IntTypeT& operator*() const { return mCurrent; }
+  IntTypeT operator*() const { return mCurrent; }
 
   /* Increment and decrement operators */
 
   IntegerIterator& operator++() { ++mCurrent; return *this; }
   IntegerIterator& operator--() { --mCurrent; return *this; }
   IntegerIterator operator++(int) { auto ret = *this; ++mCurrent; return ret; }
   IntegerIterator operator--(int) { auto ret = *this; --mCurrent; return ret; }
 
--- a/mfbt/ReverseIterator.h
+++ b/mfbt/ReverseIterator.h
@@ -8,16 +8,17 @@
  * the negative direction. (Note that not all iterators can iterate
  * in the negative direction.) */
 
 #ifndef mozilla_ReverseIterator_h
 #define mozilla_ReverseIterator_h
 
 #include "mozilla/Attributes.h"
 #include "mozilla/IteratorTraits.h"
+#include "mozilla/TypeTraits.h"
 
 namespace mozilla {
 
 template<typename IteratorT>
 class ReverseIterator
 {
 public:
   typedef typename IteratorTraits<IteratorT>::ValueType ValueType;
@@ -26,17 +27,17 @@ public:
   template<typename Iterator>
   explicit ReverseIterator(Iterator aIter)
     : mCurrent(aIter) { }
 
   template<typename Iterator>
   MOZ_IMPLICIT ReverseIterator(const ReverseIterator<Iterator>& aOther)
     : mCurrent(aOther.mCurrent) { }
 
-  ValueType& operator*() const
+  decltype(*DeclVal<IteratorT>()) operator*() const
   {
     IteratorT tmp = mCurrent;
     return *--tmp;
   }
 
   /* Increments and decrements operators */
 
   ReverseIterator& operator++() { --mCurrent; return *this; }