Bug 1469126 - Multipart Blobs should use nsMultiplexInputStream only when needed, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 18 Jun 2018 11:35:46 -0400
changeset 808199 9dc030b148fa37e4e0b849c3ca10c98e02963fe7
parent 808198 4a137fd2fcaf910648a4eb61cf9b446be336f76b
child 808200 0ae926d8f56b84e49d15272aabad19053dea80b2
push id113309
push userbmo:gl@mozilla.com
push dateMon, 18 Jun 2018 17:04:13 +0000
reviewerssmaug
bugs1469126
milestone62.0a1
Bug 1469126 - Multipart Blobs should use nsMultiplexInputStream only when needed, r=smaug
dom/file/MultipartBlobImpl.cpp
--- a/dom/file/MultipartBlobImpl.cpp
+++ b/dom/file/MultipartBlobImpl.cpp
@@ -54,25 +54,37 @@ MultipartBlobImpl::Create(nsTArray<RefPt
 }
 
 void
 MultipartBlobImpl::CreateInputStream(nsIInputStream** aStream,
                                      ErrorResult& aRv)
 {
   *aStream = nullptr;
 
+  uint32_t length = mBlobImpls.Length();
+  if (length == 0) {
+    aRv = NS_NewCStringInputStream(aStream, EmptyCString());
+    return;
+  }
+
+  if (length == 1) {
+    BlobImpl* blobImpl = mBlobImpls.ElementAt(0);
+    blobImpl->CreateInputStream(aStream, aRv);
+    return;
+  }
+
   nsCOMPtr<nsIMultiplexInputStream> stream =
     do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1");
   if (NS_WARN_IF(!stream)) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   uint32_t i;
-  for (i = 0; i < mBlobImpls.Length(); i++) {
+  for (i = 0; i < length; i++) {
     nsCOMPtr<nsIInputStream> scratchStream;
     BlobImpl* blobImpl = mBlobImpls.ElementAt(i).get();
 
     blobImpl->CreateInputStream(getter_AddRefs(scratchStream), aRv);
     if (NS_WARN_IF(aRv.Failed())) {
       return;
     }