Bug 1490235 - Use nsDependentCSubstring in AltDataOutputStreamChild::WriteDataInChunks r=mayhemer a=pascalc
authorKershaw Chang <kershaw@mozilla.com>
Tue, 25 Sep 2018 16:56:16 +0000
changeset 490087 41f214d66947e7a50012bd558e25a78e8d3aeb11
parent 490086 fb0e9934b6cea695d10551d100ffdb2aac527cd0
child 490088 92308e03be8333fdc9cb8b48aa6ffd8e90d10564
push id9901
push userebalazs@mozilla.com
push dateThu, 27 Sep 2018 11:50:27 +0000
treeherdermozilla-beta@b404112c2f6c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer, pascalc
bugs1490235
milestone63.0
Bug 1490235 - Use nsDependentCSubstring in AltDataOutputStreamChild::WriteDataInChunks r=mayhemer a=pascalc Simply replace the nsCString with nsDependentCSubstring to avoid copying the data. In this way, we can also avoid the potential OOM crash. Differential Revision: https://phabricator.services.mozilla.com/D6685
netwerk/protocol/http/AltDataOutputStreamChild.cpp
netwerk/protocol/http/AltDataOutputStreamChild.h
--- a/netwerk/protocol/http/AltDataOutputStreamChild.cpp
+++ b/netwerk/protocol/http/AltDataOutputStreamChild.cpp
@@ -54,17 +54,17 @@ void
 AltDataOutputStreamChild::ReleaseIPDLReference()
 {
   MOZ_ASSERT(mIPCOpen, "Attempt to release nonexistent IPDL reference");
   mIPCOpen = false;
   Release();
 }
 
 bool
-AltDataOutputStreamChild::WriteDataInChunks(const nsCString& data)
+AltDataOutputStreamChild::WriteDataInChunks(const nsDependentCSubstring& data)
 {
   const uint32_t kChunkSize = 128*1024;
   uint32_t next = std::min(data.Length(), kChunkSize);
   for (uint32_t i = 0; i < data.Length();
        i = next, next = std::min(data.Length(), next + kChunkSize)) {
     nsCString chunk(Substring(data, i, kChunkSize));
     if (mIPCOpen && !SendWriteData(chunk)) {
       mIPCOpen = false;
@@ -105,17 +105,17 @@ NS_IMETHODIMP
 AltDataOutputStreamChild::Write(const char * aBuf, uint32_t aCount, uint32_t *_retval)
 {
   if (!mIPCOpen) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   if (NS_FAILED(mError)) {
     return mError;
   }
-  if (WriteDataInChunks(nsCString(aBuf, aCount))) {
+  if (WriteDataInChunks(nsDependentCSubstring(aBuf, aCount))) {
     *_retval = aCount;
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
 }
 
 NS_IMETHODIMP
 AltDataOutputStreamChild::WriteFrom(nsIInputStream *aFromStream, uint32_t aCount, uint32_t *_retval)
--- a/netwerk/protocol/http/AltDataOutputStreamChild.h
+++ b/netwerk/protocol/http/AltDataOutputStreamChild.h
@@ -27,17 +27,17 @@ public:
   void ReleaseIPDLReference();
   // Saves an error code which will be reported to the writer on the next call.
   virtual mozilla::ipc::IPCResult RecvError(const nsresult& err) override;
   virtual mozilla::ipc::IPCResult RecvDeleteSelf() override;
 
 private:
   virtual ~AltDataOutputStreamChild() = default;
   // Sends data to the parent process in 256k chunks.
-  bool WriteDataInChunks(const nsCString& data);
+  bool WriteDataInChunks(const nsDependentCSubstring& data);
 
   bool mIPCOpen;
   // If there was an error opening the output stream or writing to it on the
   // parent side, this will be set to the error code. We check it before we
   // write so we can report an error to the consumer.
   nsresult mError;
 };