Bug 1353593 - Part 2: Remove wwc functions. r=froydnj
☠☠ backed out by 8b11f8753dae ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Fri, 09 Jun 2017 14:50:47 -0700
changeset 411441 c16b53fc17d9155299c00e49c8287e24c1aeb1bf
parent 411440 4bc441fc5860b4c6ebc22c3d261aa9025dfe15da
child 411442 8b11f8753daed51e71663be9976ef846498dfed7
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1353593
milestone55.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 1353593 - Part 2: Remove wwc functions. r=froydnj This removes the use of |wwc| functions in favor of char16ptr_t's implicit conversion operators. MozReview-Commit-ID: GHONYieMPla
widget/windows/IMMHandler.cpp
xpcom/base/nsSystemInfo.cpp
xpcom/ds/nsWindowsRegKey.cpp
xpcom/io/FileUtilsWin.cpp
xpcom/io/nsLocalFileWin.cpp
xpcom/io/nsNativeCharsetUtils.cpp
xpcom/string/nsString.h
--- a/widget/windows/IMMHandler.cpp
+++ b/widget/windows/IMMHandler.cpp
@@ -339,17 +339,17 @@ void
 IMMHandler::InitKeyboardLayout(nsWindow* aWindow,
                                HKL aKeyboardLayout)
 {
   UINT IMENameLength = ::ImmGetDescriptionW(aKeyboardLayout, nullptr, 0);
   if (IMENameLength) {
     // Add room for the terminating null character
     sIMEName.SetLength(++IMENameLength);
     IMENameLength =
-      ::ImmGetDescriptionW(aKeyboardLayout, wwc(sIMEName.BeginWriting()),
+      ::ImmGetDescriptionW(aKeyboardLayout, sIMEName.get(),
                            IMENameLength);
     // Adjust the length to ignore the terminating null character
     sIMEName.SetLength(IMENameLength);
   } else {
     sIMEName.Truncate();
   }
 
   WORD langID = LOWORD(aKeyboardLayout);
--- a/xpcom/base/nsSystemInfo.cpp
+++ b/xpcom/base/nsSystemInfo.cpp
@@ -224,17 +224,17 @@ nsresult GetCountryCode(nsAString& aCoun
   }
   // Get required length
   int numChars = GetGeoInfoW(geoid, GEO_ISO2, nullptr, 0, 0);
   if (!numChars) {
     return NS_ERROR_FAILURE;
   }
   // Now get the string for real
   aCountryCode.SetLength(numChars);
-  numChars = GetGeoInfoW(geoid, GEO_ISO2, wwc(aCountryCode.BeginWriting()),
+  numChars = GetGeoInfoW(geoid, GEO_ISO2, char16ptr_t(aCountryCode.BeginWriting()),
                          aCountryCode.Length(), 0);
   if (!numChars) {
     return NS_ERROR_FAILURE;
   }
 
   // numChars includes null terminator
   aCountryCode.Truncate(numChars - 1);
   return NS_OK;
--- a/xpcom/ds/nsWindowsRegKey.cpp
+++ b/xpcom/ds/nsWindowsRegKey.cpp
@@ -349,21 +349,18 @@ nsWindowsRegKey::ReadStringValue(const n
     if (resultLen > 1) {
       nsAutoString expandedResult;
       // |resultLen| includes the terminating null character
       --resultLen;
       if (!expandedResult.SetLength(resultLen, mozilla::fallible)) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
 
-      nsAString::iterator begin;
-      expandedResult.BeginWriting(begin);
-
       resultLen = ExpandEnvironmentStringsW(flatSource.get(),
-                                            wwc(begin.get()),
+                                            expandedResult.get(),
                                             resultLen + 1);
       if (resultLen <= 0) {
         rv = ERROR_UNKNOWN_FEATURE;
         aResult.Truncate();
       } else {
         rv = ERROR_SUCCESS;
         aResult = expandedResult;
       }
--- a/xpcom/io/FileUtilsWin.cpp
+++ b/xpcom/io/FileUtilsWin.cpp
@@ -56,17 +56,17 @@ HandleToFilename(HANDLE aHandle, const L
     return false;
   }
   nsAutoString mappedFilename;
   DWORD len = 0;
   SetLastError(ERROR_SUCCESS);
   do {
     mappedFilename.SetLength(mappedFilename.Length() + MAX_PATH);
     len = GetMappedFileNameW(GetCurrentProcess(), view,
-                             wwc(mappedFilename.BeginWriting()),
+                             mappedFilename.get(),
                              mappedFilename.Length());
   } while (!len && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
   if (!len) {
     return false;
   }
   mappedFilename.Truncate(len);
   return NtPathToDosPath(mappedFilename, aFilename);
 }
--- a/xpcom/io/nsLocalFileWin.cpp
+++ b/xpcom/io/nsLocalFileWin.cpp
@@ -990,17 +990,17 @@ nsLocalFile::ResolveShortcut()
     return NS_ERROR_FAILURE;
   }
 
   mResolvedPath.SetLength(MAX_PATH);
   if (mResolvedPath.Length() != MAX_PATH) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  wchar_t* resolvedPath = wwc(mResolvedPath.BeginWriting());
+  wchar_t* resolvedPath = mResolvedPath.get();
 
   // resolve this shortcut
   nsresult rv = gResolver->Resolve(mWorkingPath.get(), resolvedPath);
 
   size_t len = NS_FAILED(rv) ? 0 : wcslen(resolvedPath);
   mResolvedPath.SetLength(len);
 
   return rv;
@@ -1360,17 +1360,17 @@ nsLocalFile::Create(uint32_t aType, uint
   //                       ^--- start here
   //
   //   - UNC path:  \\machine\volume\some\path\on\this\drive
   //                                     ^--- start here
   //
   // Skip the first 'X:\' for the first form, and skip the first full
   // '\\machine\volume\' segment for the second form.
 
-  wchar_t* path = wwc(mResolvedPath.BeginWriting());
+  wchar_t* path = char16ptr_t(mResolvedPath.BeginWriting());
 
   if (path[0] == L'\\' && path[1] == L'\\') {
     // dealing with a UNC path here; skip past '\\machine\'
     path = wcschr(path + 2, L'\\');
     if (!path) {
       return NS_ERROR_FILE_INVALID_PATH;
     }
     ++path;
@@ -3738,17 +3738,17 @@ nsDriveEnumerator::Init()
   /* If the length passed to GetLogicalDriveStrings is smaller
    * than the length of the string it would return, it returns
    * the length required for the string. */
   DWORD length = GetLogicalDriveStringsW(0, 0);
   /* The string is null terminated */
   if (!mDrives.SetLength(length + 1, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
-  if (!GetLogicalDriveStringsW(length, wwc(mDrives.BeginWriting()))) {
+  if (!GetLogicalDriveStringsW(length, mDrives.get())) {
     return NS_ERROR_FAILURE;
   }
   mDrives.BeginReading(mStartOfCurrentDrive);
   mDrives.EndReading(mEndOfDrivesString);
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/xpcom/io/nsNativeCharsetUtils.cpp
+++ b/xpcom/io/nsNativeCharsetUtils.cpp
@@ -924,22 +924,18 @@ NS_CopyNativeToUnicode(const nsACString&
     resultLen += n;
   }
 
   // allocate sufficient space
   if (!aOutput.SetLength(resultLen, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   if (resultLen > 0) {
-    nsAString::iterator out_iter;
-    aOutput.BeginWriting(out_iter);
-
-    char16_t* result = out_iter.get();
-
-    ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, wwc(result), resultLen);
+    char16ptr_t result = aOutput.BeginWriting();
+    ::MultiByteToWideChar(CP_ACP, 0, buf, inputLen, result, resultLen);
   }
   return NS_OK;
 }
 
 nsresult
 NS_CopyUnicodeToNative(const nsAString&  aInput, nsACString& aOutput)
 {
   uint32_t inputLen = aInput.Length();
@@ -973,51 +969,16 @@ NS_CopyUnicodeToNative(const nsAString& 
     char* result = out_iter.get();
 
     ::WideCharToMultiByte(CP_ACP, 0, buf, inputLen, result, resultLen,
                           &defaultChar, nullptr);
   }
   return NS_OK;
 }
 
-// moved from widget/windows/nsToolkit.cpp
-int32_t
-NS_ConvertAtoW(const char* aStrInA, int aBufferSize, char16_t* aStrOutW)
-{
-  return MultiByteToWideChar(CP_ACP, 0, aStrInA, -1, wwc(aStrOutW), aBufferSize);
-}
-
-int32_t
-NS_ConvertWtoA(const char16_t* aStrInW, int aBufferSizeOut,
-               char* aStrOutA, const char* aDefault)
-{
-  if ((!aStrInW) || (!aStrOutA) || (aBufferSizeOut <= 0)) {
-    return 0;
-  }
-
-  int numCharsConverted = WideCharToMultiByte(CP_ACP, 0, char16ptr_t(aStrInW), -1,
-                                              aStrOutA, aBufferSizeOut,
-                                              aDefault, nullptr);
-
-  if (!numCharsConverted) {
-    if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
-      // Overflow, add missing null termination but return 0
-      aStrOutA[aBufferSizeOut - 1] = '\0';
-    } else {
-      // Other error, clear string and return 0
-      aStrOutA[0] = '\0';
-    }
-  } else if (numCharsConverted < aBufferSizeOut) {
-    // Add 2nd null (really necessary?)
-    aStrOutA[numCharsConverted] = '\0';
-  }
-
-  return numCharsConverted;
-}
-
 #else
 
 #include "nsReadableUtils.h"
 
 nsresult
 NS_CopyNativeToUnicode(const nsACString& aInput, nsAString& aOutput)
 {
   CopyASCIItoUTF16(aInput, aOutput);
--- a/xpcom/string/nsString.h
+++ b/xpcom/string/nsString.h
@@ -143,59 +143,16 @@ public:
     AppendUTF8toUTF16(aCString, *this);
   }
 
 private:
   // NOT TO BE IMPLEMENTED
   NS_ConvertUTF8toUTF16(char16_t) = delete;
 };
 
-
-#ifdef MOZ_USE_CHAR16_WRAPPER
-
-inline char16_t*
-wwc(wchar_t* aStr)
-{
-  return reinterpret_cast<char16_t*>(aStr);
-}
-
-inline wchar_t*
-wwc(char16_t* aStr)
-{
-  return reinterpret_cast<wchar_t*>(aStr);
-}
-
-inline const char16_t*
-wwc(const wchar_t* aStr)
-{
-  return reinterpret_cast<const char16_t*>(aStr);
-}
-
-inline const wchar_t*
-wwc(const char16_t* aStr)
-{
-  return reinterpret_cast<const wchar_t*>(aStr);
-}
-
-#else
-
-inline char16_t*
-wwc(char16_t* aStr)
-{
-  return aStr;
-}
-
-inline const char16_t*
-wwc(const char16_t* aStr)
-{
-  return aStr;
-}
-
-#endif
-
 // the following are included/declared for backwards compatibility
 typedef nsAutoString nsVoidableString;
 
 #include "nsDependentString.h"
 #include "nsLiteralString.h"
 #include "nsPromiseFlatString.h"
 
 // need to include these for backwards compatibility