Bug 1362449 - part 12 - avoid conversions in nsString Base64 decoding; r=erahm
authorNathan Froyd <froydnj@mozilla.com>
Wed, 06 Sep 2017 16:58:36 -0400
changeset 428882 981709ff412efd00b236ca2f0c76bfda6de786be
parent 428881 f2669ac73b9078fc82cbff32eb97c2f2440ce248
child 428883 0bfc1c5663505f9e394384072f9fe29b6bc91f43
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerserahm
bugs1362449
milestone57.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 1362449 - part 12 - avoid conversions in nsString Base64 decoding; r=erahm After all the previous work, we can now base64 decode nsString types without intermediate conversion steps to nsCString, which is faster and more memory-efficient.
xpcom/io/Base64.cpp
--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -591,38 +591,17 @@ nsresult
 Base64Decode(const nsACString& aBase64, nsACString& aBinary)
 {
   return Base64DecodeString(aBase64, aBinary);
 }
 
 nsresult
 Base64Decode(const nsAString& aBase64, nsAString& aBinary)
 {
-  auto truncater = mozilla::MakeScopeExit([&]() { aBinary.Truncate(); });
-
-  // XXX We should really consider decoding directly from the string, rather
-  // than making a separate copy here.
-  nsAutoCString base64;
-  if (!base64.SetCapacity(aBase64.Length(), mozilla::fallible)) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-  LossyCopyUTF16toASCII(aBase64, base64);
-
-  nsAutoCString binary;
-
-  nsresult rv = Base64Decode(base64, binary);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!CopyASCIItoUTF16(binary, aBinary, mozilla::fallible)) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  truncater.release();
-
-  return rv;
+  return Base64DecodeString(aBase64, aBinary);
 }
 
 nsresult
 Base64URLDecode(const nsACString& aBase64,
                 Base64URLDecodePaddingPolicy aPaddingPolicy,
                 FallibleTArray<uint8_t>& aBinary)
 {
   // Don't decode empty strings.