Bug 1305422 - part 6 - pass explicit end iterators for CopyTo{Upper,Lower}Case; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Thu, 29 Sep 2016 22:33:57 -0400
changeset 315877 9dc21248ab121e9d0acf01dc24d0fa297f2632ce
parent 315876 9b814ee26cd7a8d4eeb1f9e3206a4e6b37d22b2a
child 315878 caad2bb558f675154302f348a11bd23486c3a16d
push id20634
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:10:13 +0000
treeherderfx-team@afe79b010d13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1305422
milestone52.0a1
Bug 1305422 - part 6 - pass explicit end iterators for CopyTo{Upper,Lower}Case; r=erahm This change avoids calling size_forward on the iterator, which we are trying to eliminate.
xpcom/string/nsReadableUtils.cpp
--- a/xpcom/string/nsReadableUtils.cpp
+++ b/xpcom/string/nsReadableUtils.cpp
@@ -753,25 +753,27 @@ ToUpperCase(nsCSubstring& aCString)
 /**
  * A character sink for copying with case conversion.
  */
 class CopyToUpperCase
 {
 public:
   typedef char value_type;
 
-  explicit CopyToUpperCase(nsACString::iterator& aDestIter)
+  explicit CopyToUpperCase(nsACString::iterator& aDestIter,
+                           const nsACString::iterator& aEndIter)
     : mIter(aDestIter)
+    , mEnd(aEndIter)
   {
   }
 
   uint32_t
   write(const char* aSource, uint32_t aSourceLength)
   {
-    uint32_t len = XPCOM_MIN(uint32_t(mIter.size_forward()), aSourceLength);
+    uint32_t len = XPCOM_MIN(uint32_t(mEnd - mIter), aSourceLength);
     char* cp = mIter.get();
     const char* end = aSource + len;
     while (aSource != end) {
       char ch = *aSource;
       if ((ch >= 'a') && (ch <= 'z')) {
         *cp = ch - ('a' - 'A');
       } else {
         *cp = ch;
@@ -780,26 +782,27 @@ public:
       ++cp;
     }
     mIter.advance(len);
     return len;
   }
 
 protected:
   nsACString::iterator& mIter;
+  const nsACString::iterator& mEnd;
 };
 
 void
 ToUpperCase(const nsACString& aSource, nsACString& aDest)
 {
   nsACString::const_iterator fromBegin, fromEnd;
-  nsACString::iterator toBegin;
+  nsACString::iterator toBegin, toEnd;
   aDest.SetLength(aSource.Length());
 
-  CopyToUpperCase converter(aDest.BeginWriting(toBegin));
+  CopyToUpperCase converter(aDest.BeginWriting(toBegin), aDest.EndWriting(toEnd));
   copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
               converter);
 }
 
 /**
  * A character sink for case conversion.
  */
 class ConvertToLowerCase
@@ -834,25 +837,27 @@ ToLowerCase(nsCSubstring& aCString)
 /**
  * A character sink for copying with case conversion.
  */
 class CopyToLowerCase
 {
 public:
   typedef char value_type;
 
-  explicit CopyToLowerCase(nsACString::iterator& aDestIter)
+  explicit CopyToLowerCase(nsACString::iterator& aDestIter,
+                           const nsACString::iterator& aEndIter)
     : mIter(aDestIter)
+    , mEnd(aEndIter)
   {
   }
 
   uint32_t
   write(const char* aSource, uint32_t aSourceLength)
   {
-    uint32_t len = XPCOM_MIN(uint32_t(mIter.size_forward()), aSourceLength);
+    uint32_t len = XPCOM_MIN(uint32_t(mEnd - mIter), aSourceLength);
     char* cp = mIter.get();
     const char* end = aSource + len;
     while (aSource != end) {
       char ch = *aSource;
       if ((ch >= 'A') && (ch <= 'Z')) {
         *cp = ch + ('a' - 'A');
       } else {
         *cp = ch;
@@ -861,26 +866,27 @@ public:
       ++cp;
     }
     mIter.advance(len);
     return len;
   }
 
 protected:
   nsACString::iterator& mIter;
+  const nsACString::iterator& mEnd;
 };
 
 void
 ToLowerCase(const nsACString& aSource, nsACString& aDest)
 {
   nsACString::const_iterator fromBegin, fromEnd;
-  nsACString::iterator toBegin;
+  nsACString::iterator toBegin, toEnd;
   aDest.SetLength(aSource.Length());
 
-  CopyToLowerCase converter(aDest.BeginWriting(toBegin));
+  CopyToLowerCase converter(aDest.BeginWriting(toBegin), aDest.EndWriting(toEnd));
   copy_string(aSource.BeginReading(fromBegin), aSource.EndReading(fromEnd),
               converter);
 }
 
 bool
 ParseString(const nsACString& aSource, char aDelimiter,
             nsTArray<nsCString>& aArray)
 {