Bug 1492204 - Part 1: Stop using deprecated string writing iterators. r=froydnj
authorEric Rahm <erahm@mozilla.com>
Tue, 18 Sep 2018 09:44:57 -0700
changeset 437325 4d671b85f851a5327191d9642a90322ac75430bf
parent 437324 c4923d4f4dc05149f4c4762bb867ec6470c959ee
child 437326 1dc310ee7bf7b31de2f18a710cd8ebf5500c32e1
push id34675
push userbtara@mozilla.com
push dateWed, 19 Sep 2018 21:58:47 +0000
treeherdermozilla-central@9812141ec782 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1492204
milestone64.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 1492204 - Part 1: Stop using deprecated string writing iterators. r=froydnj This switches over the few remaining usages of the deprecated BeginWriting/EndWriting(iterator&) functions to the more standard BeginWriting/EndWriting() functions.
dom/storage/StorageUtils.cpp
dom/xslt/base/txDouble.cpp
netwerk/base/nsStandardURL.cpp
parser/htmlparser/nsScannerString.cpp
toolkit/xre/nsXREDirProvider.cpp
xpcom/ds/nsWindowsRegKey.cpp
xpcom/io/nsBinaryStream.cpp
xpcom/io/nsNativeCharsetUtils.cpp
--- a/dom/storage/StorageUtils.cpp
+++ b/dom/storage/StorageUtils.cpp
@@ -86,18 +86,17 @@ PrincipalsEqual(nsIPrincipal* aObjectPri
 void
 ReverseString(const nsACString& aSource, nsACString& aResult)
 {
   nsACString::const_iterator sourceBegin, sourceEnd;
   aSource.BeginReading(sourceBegin);
   aSource.EndReading(sourceEnd);
 
   aResult.SetLength(aSource.Length());
-  nsACString::iterator destEnd;
-  aResult.EndWriting(destEnd);
+  auto destEnd = aResult.EndWriting();
 
   while (sourceBegin != sourceEnd) {
     *(--destEnd) = *sourceBegin;
     ++sourceBegin;
   }
 }
 
 nsresult
--- a/dom/xslt/base/txDouble.cpp
+++ b/dom/xslt/base/txDouble.cpp
@@ -174,18 +174,18 @@ void txDouble::toString(double aValue, n
         length = intDigits;
     }
     if (aValue < 0)
         ++length;
     // grow the string
     uint32_t oldlength = aDest.Length();
     if (!aDest.SetLength(oldlength + length, mozilla::fallible))
         return; // out of memory
-    nsAString::iterator dest;
-    aDest.BeginWriting(dest).advance(int32_t(oldlength));
+    auto dest = aDest.BeginWriting();
+    std::advance(dest, oldlength);
     if (aValue < 0) {
         *dest = '-'; ++dest;
     }
     int i;
     // leading zeros
     if (intDigits < 1) {
         *dest = '0'; ++dest;
         *dest = '.'; ++dest;
--- a/netwerk/base/nsStandardURL.cpp
+++ b/netwerk/base/nsStandardURL.cpp
@@ -1506,20 +1506,18 @@ nsStandardURL::SetSpecWithEncoding(const
     // Make a backup of the curent URL
     nsStandardURL prevURL(false,false);
     prevURL.CopyMembers(this, eHonorRef, EmptyCString());
     Clear();
 
     if (IsSpecialProtocol(filteredURI)) {
         // Bug 652186: Replace all backslashes with slashes when parsing paths
         // Stop when we reach the query or the hash.
-        nsAutoCString::iterator start;
-        nsAutoCString::iterator end;
-        filteredURI.BeginWriting(start);
-        filteredURI.EndWriting(end);
+        auto start = filteredURI.BeginWriting();
+        auto end = filteredURI.EndWriting();
         while (start != end) {
             if (*start == '?' || *start == '#') {
                 break;
             }
             if (*start == '\\') {
                 *start = '/';
             }
             start++;
@@ -2388,20 +2386,18 @@ nsStandardURL::Resolve(const nsACString 
     nsAutoCString baseProtocol(Scheme());
 
     // We need to do backslash replacement for the following cases:
     // 1. The input is an absolute path with a http/https/ftp scheme
     // 2. The input is a relative path, and the base URL has a http/https/ftp scheme
     if ((protocol.IsEmpty() && IsSpecialProtocol(baseProtocol)) ||
          IsSpecialProtocol(protocol)) {
 
-        nsAutoCString::iterator start;
-        nsAutoCString::iterator end;
-        buf.BeginWriting(start);
-        buf.EndWriting(end);
+        auto start = buf.BeginWriting();
+        auto end = buf.EndWriting();
         while (start != end) {
             if (*start == '?' || *start == '#') {
                 break;
             }
             if (*start == '\\') {
                 *start = '/';
             }
             start++;
--- a/parser/htmlparser/nsScannerString.cpp
+++ b/parser/htmlparser/nsScannerString.cpp
@@ -432,21 +432,21 @@ nsScannerSharedSubstring::MakeMutable()
 }
 
   /**
    * utils -- based on code from nsReadableUtils.cpp
    */
 
 // private helper function
 static inline
-nsAString::iterator&
-copy_multifragment_string( nsScannerIterator& first, const nsScannerIterator& last, nsAString::iterator& result )
+nsAString::char_iterator&
+copy_multifragment_string( nsScannerIterator& first, const nsScannerIterator& last, nsAString::char_iterator& result )
   {
     typedef nsCharSourceTraits<nsScannerIterator> source_traits;
-    typedef nsCharSinkTraits<nsAString::iterator> sink_traits;
+    typedef nsCharSinkTraits<nsAString::char_iterator> sink_traits;
 
     while ( first != last )
       {
         uint32_t distance = source_traits::readable_distance(first, last);
         sink_traits::write(result, source_traits::read(first), distance);
         NS_ASSERTION(distance > 0, "|copy_multifragment_string| will never terminate");
         source_traits::advance(first, distance);
       }
@@ -454,30 +454,28 @@ copy_multifragment_string( nsScannerIter
     return result;
   }
 
 bool
 CopyUnicodeTo( const nsScannerIterator& aSrcStart,
                const nsScannerIterator& aSrcEnd,
                nsAString& aDest )
   {
-    nsAString::iterator writer;
-
     mozilla::CheckedInt<nsAString::size_type> distance(Distance(aSrcStart, aSrcEnd));
     if (!distance.isValid()) {
       return false; // overflow detected
     }
 
     if (!aDest.SetLength(distance.value(), mozilla::fallible)) {
       aDest.Truncate();
       return false; // out of memory
     }
-    aDest.BeginWriting(writer);
+    auto writer = aDest.BeginWriting();
     nsScannerIterator fromBegin(aSrcStart);
-    
+
     copy_multifragment_string(fromBegin, aSrcEnd, writer);
     return true;
   }
 
 bool
 AppendUnicodeTo( const nsScannerIterator& aSrcStart,
                  const nsScannerIterator& aSrcEnd,
                  nsScannerSharedSubstring& aDest )
@@ -493,29 +491,29 @@ AppendUnicodeTo( const nsScannerIterator
     return AppendUnicodeTo(aSrcStart, aSrcEnd, aDest.writable());
   }
 
 bool
 AppendUnicodeTo( const nsScannerIterator& aSrcStart,
                  const nsScannerIterator& aSrcEnd,
                  nsAString& aDest )
   {
-    nsAString::iterator writer;
     const nsAString::size_type oldLength = aDest.Length();
     CheckedInt<nsAString::size_type> newLen(Distance(aSrcStart, aSrcEnd));
     newLen += oldLength;
     if (!newLen.isValid()) {
       return false; // overflow detected
     }
 
     if (!aDest.SetLength(newLen.value(), mozilla::fallible))
       return false; // out of memory
-    aDest.BeginWriting(writer).advance(oldLength);
+    auto writer = aDest.BeginWriting();
+    std::advance(writer, oldLength);
     nsScannerIterator fromBegin(aSrcStart);
-    
+
     copy_multifragment_string(fromBegin, aSrcEnd, writer);
     return true;
   }
 
 bool
 FindCharInReadable( char16_t aChar,
                     nsScannerIterator& aSearchStart,
                     const nsScannerIterator& aSearchEnd )
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -1129,21 +1129,20 @@ GetRegWindowsAppDataFolder(bool aLocal, 
   DWORD resultLen = size / 2;
 
   if (!_retval.SetLength(resultLen, mozilla::fallible)) {
     ::RegCloseKey(key);
     _retval.SetLength(0);
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  nsAString::iterator begin;
-  _retval.BeginWriting(begin);
+  auto begin = _retval.BeginWriting();
 
   res = RegQueryValueExW(key, (aLocal ? L"Local AppData" : L"AppData"),
-                         nullptr, nullptr, (LPBYTE) begin.get(), &size);
+                         nullptr, nullptr, (LPBYTE) begin, &size);
   ::RegCloseKey(key);
   if (res != ERROR_SUCCESS) {
     _retval.SetLength(0);
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   if (!_retval.CharAt(resultLen - 1)) {
     // It was already null terminated.
--- a/xpcom/ds/nsWindowsRegKey.cpp
+++ b/xpcom/ds/nsWindowsRegKey.cpp
@@ -326,20 +326,19 @@ nsWindowsRegKey::ReadStringValue(const n
 
   // |size| may or may not include the terminating null character.
   DWORD resultLen = size / 2;
 
   if (!aResult.SetLength(resultLen, mozilla::fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  nsAString::iterator begin;
-  aResult.BeginWriting(begin);
+  auto begin = aResult.BeginWriting();
 
-  rv = RegQueryValueExW(mKey, flatName.get(), 0, &type, (LPBYTE)begin.get(),
+  rv = RegQueryValueExW(mKey, flatName.get(), 0, &type, (LPBYTE)begin,
                         &size);
 
   if (!aResult.CharAt(resultLen - 1)) {
     // The string passed to us had a null terminator in the final position.
     aResult.Truncate(resultLen - 1);
   }
 
   // Expand the environment variables if needed
@@ -418,21 +417,20 @@ nsWindowsRegKey::ReadBinaryValue(const n
     aResult.Truncate();
     return NS_OK;
   }
 
   if (!aResult.SetLength(size, mozilla::fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  nsACString::iterator begin;
-  aResult.BeginWriting(begin);
+  auto begin = aResult.BeginWriting();
 
   rv = RegQueryValueExW(mKey, PromiseFlatString(aName).get(), 0, nullptr,
-                        (LPBYTE)begin.get(), &size);
+                        (LPBYTE)begin, &size);
   return (rv == ERROR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 nsWindowsRegKey::WriteStringValue(const nsAString& aName,
                                   const nsAString& aValue)
 {
   if (NS_WARN_IF(!mKey)) {
--- a/xpcom/io/nsBinaryStream.cpp
+++ b/xpcom/io/nsBinaryStream.cpp
@@ -784,21 +784,18 @@ nsBinaryInputStream::ReadString(nsAStrin
     return NS_OK;
   }
 
   // pre-allocate output buffer, and get direct access to buffer...
   if (!aString.SetLength(length, mozilla::fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  nsAString::iterator start;
-  aString.BeginWriting(start);
-
   WriteStringClosure closure;
-  closure.mWriteCursor = start.get();
+  closure.mWriteCursor = aString.BeginWriting();
   closure.mHasCarryoverByte = false;
 
   rv = ReadSegments(WriteSegmentToString, &closure,
                     length * sizeof(char16_t), &bytesRead);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -88,24 +88,21 @@ NS_CopyUnicodeToNative(const nsAString& 
     resultLen += n;
   }
 
   // allocate sufficient space
   if (!aOutput.SetLength(resultLen, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   if (resultLen > 0) {
-    nsACString::iterator out_iter;
-    aOutput.BeginWriting(out_iter);
+    char* result = aOutput.BeginWriting();
 
     // default "defaultChar" is '?', which is an illegal character on windows
     // file system.  That will cause file uncreatable. Change it to '_'
     const char defaultChar = '_';
 
-    char* result = out_iter.get();
-
     ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, result, resultLen,
                           &defaultChar, nullptr);
   }
   return NS_OK;
 }
 
 #endif