Bug 1485029 - Use SIMD for PopulateBufferForBinaryString() in FileReader.cpp. r=smaug
authorHenri Sivonen <hsivonen@hsivonen.fi>
Wed, 22 Aug 2018 13:59:43 +0000
changeset 481223 06caf48cb3b5001f8b67b80e6c7c75d306c05b60
parent 481222 7f64306b8f830ed29d4ee72414449ea67763c242
child 481224 0f52720def8442a28e0542505e6a24e4647d6c1a
push id232
push userfmarier@mozilla.com
push dateWed, 05 Sep 2018 20:45:54 +0000
reviewerssmaug
bugs1485029
milestone63.0a1
Bug 1485029 - Use SIMD for PopulateBufferForBinaryString() in FileReader.cpp. r=smaug MozReview-Commit-ID: Gwoj13lFJsJ Differential Revision: https://phabricator.services.mozilla.com/D3889
dom/file/FileReader.cpp
--- a/dom/file/FileReader.cpp
+++ b/dom/file/FileReader.cpp
@@ -22,16 +22,17 @@
 #include "mozilla/dom/WorkerScope.h"
 #include "mozilla/Encoding.h"
 #include "nsAlgorithm.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDOMJSUtils.h"
 #include "nsError.h"
 #include "nsNetUtil.h"
 #include "xpcpublic.h"
+#include "nsReadableUtils.h"
 
 namespace mozilla {
 namespace dom {
 
 #define ABORT_STR "abort"
 #define LOAD_STR "load"
 #define LOADSTART_STR "loadstart"
 #define LOADEND_STR "loadend"
@@ -260,23 +261,18 @@ FileReader::DoAsyncWait()
 }
 
 namespace {
 
 void
 PopulateBufferForBinaryString(char16_t* aDest, const char* aSource,
                               uint32_t aCount)
 {
-  const unsigned char* source = (const unsigned char*)aSource;
-  char16_t* end = aDest + aCount;
-  while (aDest != end) {
-    *aDest = *source;
-    ++aDest;
-    ++source;
-  }
+  // Zero-extend each char to char16_t.
+  ConvertLatin1toUTF16(MakeSpan(aSource, aCount), MakeSpan(aDest, aCount));
 }
 
 nsresult
 ReadFuncBinaryString(nsIInputStream* aInputStream,
                      void* aClosure,
                      const char* aFromRawSegment,
                      uint32_t aToOffset,
                      uint32_t aCount,