Bug 1435899 - Use nsStringStream for the data channel buffer. r=bz
☠☠ backed out by 5bc50083d6fd ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Fri, 02 Feb 2018 12:42:55 -0800
changeset 752966 1fa8c5b051ac7a91c3856610fe99b8af0066cb54
parent 752965 fc5cbc7e0d7ff28ed81f802a4973e2e8634cfe61
child 752967 73255f988eb133d3f515687cead96259d6fc0bb9
push id98429
push usermak77@bonardo.net
push dateFri, 09 Feb 2018 10:14:12 +0000
reviewersbz
bugs1435899
milestone60.0a1
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,28 @@ 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),
-                    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;