Bug 1306616 - part 2 - remove nsWritingIterator<T>::write; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Mon, 03 Oct 2016 17:21:52 -0400
changeset 316257 5c7d19f4aed921f9ff2dba1206c71669d76bb7f0
parent 316256 1f5b932a4fade74aaa2b9e92417adae3cd942a70
child 316258 44d130271ebc4f957f32de1635b22eeaea26d787
push id20649
push userphilringnalda@gmail.com
push dateTue, 04 Oct 2016 03:52:28 +0000
treeherderfx-team@96c39d552134 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1306616
milestone52.0a1
Bug 1306616 - part 2 - remove nsWritingIterator<T>::write; r=erahm Iterators shouldn't have methods like write(); if you need to write to an iterator, that logic should be handled by something outside of the iterator...which also explains why we have a specialization of nsCharTraits<nsWritingIterator<T>>. The HTML parser wants this for its own reasons, so we have to make sure it continues to work.
xpcom/string/nsStringIterator.h
--- a/xpcom/string/nsStringIterator.h
+++ b/xpcom/string/nsStringIterator.h
@@ -200,38 +200,40 @@ public:
       NS_ASSERTION(step < 0,
                    "can't advance (backward) a writing iterator beyond the end of a string");
 
       mPosition += step;
     }
     return *this;
   }
 
-  void write(const value_type* aS, uint32_t aN)
-  {
-    NS_ASSERTION(mEnd - mPosition > 0,
-                 "You can't |write| into an |nsWritingIterator| with no space!");
-
-    nsCharTraits<value_type>::move(mPosition, aS, aN);
-    advance(difference_type(aN));
-  }
-
   // We return an unsigned type here (with corresponding assert) rather than
   // the more usual difference_type because we want to make this class go
   // away in favor of mozilla::RangedPtr.  Since RangedPtr has the same
   // requirement we are enforcing here, the transition ought to be much
   // smoother.
   size_type operator-(const self_type& aOther) const
   {
     MOZ_ASSERT(mPosition >= aOther.mPosition);
     return mPosition - aOther.mPosition;
   }
 };
 
 template <class CharT>
+struct nsCharSinkTraits<nsWritingIterator<CharT>>
+{
+  static void
+  write(nsWritingIterator<CharT>& aIter, const CharT* aStr, uint32_t aN)
+  {
+    nsCharTraits<CharT>::move(aIter.get(), aStr, aN);
+    aIter.advance(aN);
+  }
+};
+
+template <class CharT>
 inline bool
 operator==(const nsReadingIterator<CharT>& aLhs,
            const nsReadingIterator<CharT>& aRhs)
 {
   return aLhs.get() == aRhs.get();
 }
 
 template <class CharT>