Bug 1344615: Rewrite a few straggling users of NS_String* APIs. r=bsmedberg
authorDavid Major <dmajor@mozilla.com>
Mon, 06 Mar 2017 17:52:09 +1300
changeset 396586 d5973f50d8664b9599919d13075a7a7c1e50da0d
parent 396585 e33e742b3302c74d4149bf7830ca392ff5fd9c24
child 396587 3733b20177e3c0b0dea98b8b9093e62e0ecbcbbf
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1344615
milestone54.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 1344615: Rewrite a few straggling users of NS_String* APIs. r=bsmedberg I've moved the body of the APIs into the few remaining callers. MozReview-Commit-ID: 9ALoSmQHkGM
dom/json/nsJSON.cpp
dom/media/android/AndroidMediaPluginHost.cpp
intl/locale/windows/nsWin32Locale.cpp
intl/unicharutil/util/nsUnicharUtils.cpp
parser/html/nsHtml5TreeOperation.h
widget/windows/nsDataObj.cpp
--- a/dom/json/nsJSON.cpp
+++ b/dom/json/nsJSON.cpp
@@ -358,18 +358,18 @@ nsJSONWriter::WriteToStream(nsIOutputStr
 NS_IMETHODIMP
 nsJSON::Decode(const nsAString& json, JSContext* cx,
                JS::MutableHandle<JS::Value> aRetval)
 {
   nsresult rv = WarnDeprecatedMethod(DecodeWarning);
   if (NS_FAILED(rv))
     return rv;
 
-  const char16_t *data;
-  uint32_t len = NS_StringGetData(json, &data);
+  const char16_t *data = json.BeginReading();
+  uint32_t len = json.Length();
   nsCOMPtr<nsIInputStream> stream;
   rv = NS_NewByteInputStream(getter_AddRefs(stream),
                              reinterpret_cast<const char*>(data),
                              len * sizeof(char16_t),
                              NS_ASSIGNMENT_DEPEND);
   NS_ENSURE_SUCCESS(rv, rv);
   return DecodeInternal(cx, stream, len, false, aRetval);
 }
--- a/dom/media/android/AndroidMediaPluginHost.cpp
+++ b/dom/media/android/AndroidMediaPluginHost.cpp
@@ -225,18 +225,18 @@ AndroidMediaPluginHost::AndroidMediaPlug
 AndroidMediaPluginHost::~AndroidMediaPluginHost() {
   mResourceServer->Stop();
   MOZ_COUNT_DTOR(AndroidMediaPluginHost);
 }
 
 bool AndroidMediaPluginHost::FindDecoder(const MediaContainerType& aMimeType,
                                          MediaCodecs* aCodecs)
 {
-  const char *chars;
-  size_t len = NS_CStringGetData(aMimeType.Type().AsString(), &chars, nullptr);
+  const char *chars = aMimeType.Type().AsString().BeginReading();
+  size_t len = aMimeType.Type().AsString().Length();
   for (size_t n = 0; n < mPlugins.Length(); ++n) {
     Manifest *plugin = mPlugins[n];
     const char* const *codecs;
     if (plugin->CanDecode(chars, len, &codecs)) {
       if (aCodecs) {
         nsString codecsString;
         for (const char* const* codec = codecs; *codec; ++codec) {
           if (codecsString.IsEmpty()) {
@@ -257,18 +257,18 @@ MPAPI::Decoder *AndroidMediaPluginHost::
 {
   NS_ENSURE_TRUE(aResource, nullptr);
 
   nsAutoPtr<Decoder> decoder(new Decoder());
   if (!decoder) {
     return nullptr;
   }
 
-  const char *chars;
-  size_t len = NS_CStringGetData(aMimeType.Type().AsString(), &chars, nullptr);
+  const char *chars = aMimeType.Type().AsString().BeginReading();
+  size_t len = aMimeType.Type().AsString().Length();
   for (size_t n = 0; n < mPlugins.Length(); ++n) {
     Manifest *plugin = mPlugins[n];
     const char* const *codecs;
     if (!plugin->CanDecode(chars, len, &codecs)) {
       continue;
     }
 
     nsCString url;
--- a/intl/locale/windows/nsWin32Locale.cpp
+++ b/intl/locale/windows/nsWin32Locale.cpp
@@ -492,18 +492,18 @@ nsWin32Locale::GetPlatformLocale(const n
   }
 
   char    locale_string[9] = {'\0','\0','\0','\0','\0','\0','\0','\0','\0'};
   char*   language_code;
   char*   country_code;
   size_t  i, j;
 
   // parse the locale
-  const char16_t* data;
-  j = NS_StringGetData(locale, &data);
+  const char16_t* data = locale.BeginReading();
+  j = locale.Length();
   for (i = 0; i < 7 && i < j; i++) {
     locale_string[i] = data[i] == '-' ? '\0' : data[i];
   }
 
   language_code = locale_string;
   country_code = locale_string + strlen(locale_string) + 1;
 
   // convert parsed locale to Windows LCID
--- a/intl/unicharutil/util/nsUnicharUtils.cpp
+++ b/intl/unicharutil/util/nsUnicharUtils.cpp
@@ -58,21 +58,22 @@ ToLowerCase(nsAString& aString)
   char16_t *buf = aString.BeginWriting();
   ToLowerCase(buf, buf, aString.Length());
 }
 
 void
 ToLowerCase(const nsAString& aSource,
             nsAString& aDest)
 {
-  const char16_t *in;
-  char16_t *out;
-  uint32_t len = NS_StringGetData(aSource, &in);
-  NS_StringGetMutableData(aDest, len, &out);
-  NS_ASSERTION(out, "Uh...");
+  const char16_t *in = aSource.BeginReading();
+  uint32_t len = aSource.Length();
+
+  aDest.SetLength(len);
+  char16_t *out = aDest.BeginWriting();
+
   ToLowerCase(in, out, len);
 }
 
 uint32_t
 ToLowerCaseASCII(const uint32_t aChar)
 {
   return ToLowerCaseASCII_inline(aChar);
 }
@@ -83,21 +84,22 @@ ToUpperCase(nsAString& aString)
   char16_t *buf = aString.BeginWriting();
   ToUpperCase(buf, buf, aString.Length());
 }
 
 void
 ToUpperCase(const nsAString& aSource,
             nsAString& aDest)
 {
-  const char16_t *in;
-  char16_t *out;
-  uint32_t len = NS_StringGetData(aSource, &in);
-  NS_StringGetMutableData(aDest, len, &out);
-  NS_ASSERTION(out, "Uh...");
+  const char16_t *in = aSource.BeginReading();
+  uint32_t len = aSource.Length();
+
+  aDest.SetLength(len);
+  char16_t *out = aDest.BeginWriting();
+
   ToUpperCase(in, out, len);
 }
 
 #ifdef MOZILLA_INTERNAL_API
 
 int32_t
 nsCaseInsensitiveStringComparator::operator()(const char16_t* lhs,
                                               const char16_t* rhs,
--- a/parser/html/nsHtml5TreeOperation.h
+++ b/parser/html/nsHtml5TreeOperation.h
@@ -413,17 +413,17 @@ class nsHtml5TreeOperation {
       mThree.integer = aLineNumber;
     }
 
     inline void Init(eHtml5TreeOperation aOpCode, const nsAString& aString)
     {
       NS_PRECONDITION(mOpCode == eTreeOpUninitialized,
         "Op code must be uninitialized when initializing.");
 
-      char16_t* str = NS_StringCloneData(aString);
+      char16_t* str = ToNewUnicode(aString);
       mOpCode = aOpCode;
       mOne.unicharPtr = str;
     }
     
     inline void Init(eHtml5TreeOperation aOpCode,
                      nsIContentHandle* aNode,
                      int32_t aInt)
     {
--- a/widget/windows/nsDataObj.cpp
+++ b/widget/windows/nsDataObj.cpp
@@ -1594,17 +1594,17 @@ HRESULT nsDataObj::DropTempFile(FORMATET
     nsCString filename;
     nsAutoString wideFileName;
     nsCOMPtr<nsIURI> sourceURI;
     HRESULT res;
     res = GetDownloadDetails(getter_AddRefs(sourceURI),
       wideFileName);
     if (FAILED(res))
       return res;
-    NS_UTF16ToCString(wideFileName, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, filename);
+    NS_CopyUnicodeToNative(wideFileName, filename);
 
     dropFile->AppendNative(filename);
     rv = dropFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660);
     if (NS_FAILED(rv))
       return E_FAIL;
 
     // Cache the temp file so we can delete it later and so
     // it doesn't get recreated over and over on multiple calls
@@ -2082,17 +2082,17 @@ HRESULT nsDataObj::GetFileDescriptor_ISt
   res = GetDownloadDetails(getter_AddRefs(sourceURI), wideFileName);
   if (FAILED(res))
   {
     ::GlobalFree(fileGroupDescHandle);
     return res;
   }
 
   nsAutoCString nativeFileName;
-  NS_UTF16ToCString(wideFileName, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, nativeFileName);
+  NS_CopyUnicodeToNative(wideFileName, nativeFileName);
   
   strncpy(fileGroupDescA->fgd[0].cFileName, nativeFileName.get(), NS_MAX_FILEDESCRIPTOR - 1);
   fileGroupDescA->fgd[0].cFileName[NS_MAX_FILEDESCRIPTOR - 1] = '\0';
 
   // one file in the file block
   fileGroupDescA->cItems = 1;
   fileGroupDescA->fgd[0].dwFlags = FD_PROGRESSUI;