Bug 1435899 - Use nsStringStream for the data channel buffer. r=bz
authorEric Rahm <erahm@mozilla.com>
Fri, 02 Feb 2018 12:42:55 -0800
changeset 504371 c4029bc621f59edca2c3e0011ca50747be81b2c7
parent 504370 5461b62599d722d0c78b8f212653817d2d718362
child 504372 c48931864919067283a60b9627690d356058161c
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1435899
milestone65.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 1435899 - Use nsStringStream for the data channel buffer. r=bz A pipe is no longer used for the input stream, instead we use a string stream which in most cases will be able to share the string data buffer rather than copying it.
netwerk/protocol/data/nsDataChannel.cpp
--- a/netwerk/protocol/data/nsDataChannel.cpp
+++ b/netwerk/protocol/data/nsDataChannel.cpp
@@ -3,22 +3,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // data implementation
 
 #include "nsDataChannel.h"
 
 #include "mozilla/Base64.h"
-#include "nsIOService.h"
 #include "nsDataHandler.h"
-#include "nsIPipe.h"
 #include "nsIInputStream.h"
-#include "nsIOutputStream.h"
 #include "nsEscape.h"
+#include "nsStringStream.h"
 
 using namespace mozilla;
 
 /**
  * Helper for performing a fallible unescape.
  *
  * @param aStr The string to unescape.
  * @param aBuffer Buffer to unescape into if necessary.
@@ -81,36 +79,27 @@ nsDataChannel::OpenContentStream(bool as
         // Don't allow spaces in base64-encoded content. This is only
         // relevant for escaped spaces; other spaces are stripped in
         // NewURI. We know there were no escaped spaces if the data buffer
         // wasn't used in |Unescape|.
         unescapedBuffer.StripWhitespace();
     }
 
     nsCOMPtr<nsIInputStream> bufInStream;
-    nsCOMPtr<nsIOutputStream> bufOutStream;
-
-    // create an unbounded pipe.
-    rv = NS_NewPipe(getter_AddRefs(bufInStream),
-                    getter_AddRefs(bufOutStream),
-                    net::nsIOService::gDefaultSegmentSize,
-                    UINT32_MAX,
-                    async, true);
-    if (NS_FAILED(rv))
-        return rv;
-
     uint32_t contentLen;
     if (lBase64) {
         nsAutoCString decodedData;
         rv = Base64Decode(data, decodedData);
         NS_ENSURE_SUCCESS(rv, rv);
 
-        rv = bufOutStream->Write(decodedData.get(), decodedData.Length(), &contentLen);
+        contentLen = decodedData.Length();
+        rv = NS_NewCStringInputStream(getter_AddRefs(bufInStream), decodedData);
     } else {
-        rv = bufOutStream->Write(data.Data(), data.Length(), &contentLen);
+        contentLen = data.Length();
+        rv = NS_NewCStringInputStream(getter_AddRefs(bufInStream), data);
     }
 
     if (NS_FAILED(rv))
         return rv;
 
     SetContentType(contentType);
     SetContentCharset(contentCharset);
     mContentLength = contentLen;