Bug 1444329 - Remove nsIScriptableUnicodeConverter::convertFromByteArray. r=hsivonen
authorMark Banner <standard8@mozilla.com>
Mon, 04 Jun 2018 11:25:54 +0100
changeset 421350 22c2645c283cbff140a25290936e2d3ccb4698bf
parent 421349 e0821414fc6ef41bb655f50dd3c67a8d1bf28b45
child 421351 c9c090ac9e2461e17d0333a7f10ae087c9315c99
push id34092
push useraiakab@mozilla.com
push dateTue, 05 Jun 2018 21:57:17 +0000
treeherdermozilla-central@0bb149ce1d1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1444329
milestone62.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 1444329 - Remove nsIScriptableUnicodeConverter::convertFromByteArray. r=hsivonen MozReview-Commit-ID: IPgCK6slIqj
intl/uconv/nsIScriptableUConv.idl
intl/uconv/nsScriptableUConv.cpp
--- a/intl/uconv/nsIScriptableUConv.idl
+++ b/intl/uconv/nsIScriptableUConv.idl
@@ -37,22 +37,16 @@ interface nsIScriptableUnicodeConverter 
   ACString Finish();
 
   /**
    * Converts the data from one Charset to Unicode.
    */
   AString ConvertToUnicode(in ACString aSrc);
 
   /**
-   * Converts an array of bytes to a unicode string.
-   */
-  AString convertFromByteArray([const,array,size_is(aCount)] in octet aData,
-                               in unsigned long aCount);
-
-  /**
    * Convert a unicode string to an array of bytes. Finish does not need to be
    * called.
    */
   void convertToByteArray(in AString aString,
                           [optional] out unsigned long aLen,
                           [array, size_is(aLen),retval] out octet aData);
 
   /**
--- a/intl/uconv/nsScriptableUConv.cpp
+++ b/intl/uconv/nsScriptableUConv.cpp
@@ -109,40 +109,31 @@ nsScriptableUnicodeConverter::Finish(nsA
   mDecoder->Encoding()->NewDecoderWithBOMRemovalInto(*mDecoder);
   mEncoder->Encoding()->NewEncoderInto(*mEncoder);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScriptableUnicodeConverter::ConvertToUnicode(const nsACString& aSrc, nsAString& _retval)
 {
-  return ConvertFromByteArray(
-    reinterpret_cast<const uint8_t*>(aSrc.BeginReading()),
-    aSrc.Length(),
-    _retval);
-}
-
-NS_IMETHODIMP
-nsScriptableUnicodeConverter::ConvertFromByteArray(const uint8_t* aData,
-                                                   uint32_t aCount,
-                                                   nsAString& _retval)
-{
   if (!mDecoder)
     return NS_ERROR_FAILURE;
 
-  CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(aCount);
+  uint32_t length = aSrc.Length();
+
+  CheckedInt<size_t> needed = mDecoder->MaxUTF16BufferLength(length);
   if (!needed.isValid() || needed.value() > UINT32_MAX) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   if (!_retval.SetLength(needed.value(), fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
-  auto src = MakeSpan(aData, aCount);
+  auto src = MakeSpan(reinterpret_cast<const uint8_t*>(aSrc.BeginReading()), length);
   uint32_t result;
   size_t read;
   size_t written;
   bool hadErrors;
   // The UTF-8 decoder used to throw regardless of the error behavior.
   // Simulating the old behavior for compatibility with legacy callers.
   // If callers want control over the behavior, they should switch to
   // TextDecoder.
@@ -152,17 +143,17 @@ nsScriptableUnicodeConverter::ConvertFro
     if (result != kInputEmpty) {
       return NS_ERROR_UDEC_ILLEGALINPUT;
     }
   } else {
     Tie(result, read, written, hadErrors) =
       mDecoder->DecodeToUTF16(src, _retval, false);
   }
   MOZ_ASSERT(result == kInputEmpty);
-  MOZ_ASSERT(read == aCount);
+  MOZ_ASSERT(read == length);
   MOZ_ASSERT(written <= needed.value());
   Unused << hadErrors;
   if (!_retval.SetLength(written, fallible)) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
   return NS_OK;
 }