Bug 1335989 - Avoid a second copy when sending substrings through IPC. r=billm draft
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 15 Feb 2017 16:26:04 -0800
changeset 484905 9355c5a630c6ec417ed6b9ea13b743f9b885e282
parent 484195 2979580ba0e787a89e52f0667eb2504b6fad8349
child 545898 5c0654503560a38255de45bef8364ed25c7ccf82
push id45599
push userbmo:mrbkap@mozilla.com
push dateThu, 16 Feb 2017 00:26:25 +0000
reviewersbillm
bugs1335989
milestone54.0a1
Bug 1335989 - Avoid a second copy when sending substrings through IPC. r=billm MozReview-Commit-ID: HF27bYPH7Uq
ipc/glue/IPCMessageUtils.h
ipc/ipdl/ipdl/builtin.py
netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl
netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
netwerk/protocol/wyciwyg/WyciwygChannelParent.h
--- a/ipc/glue/IPCMessageUtils.h
+++ b/ipc/glue/IPCMessageUtils.h
@@ -411,16 +411,28 @@ struct ParamTraits<nsString> : ParamTrai
 };
 
 template <>
 struct ParamTraits<nsLiteralString> : ParamTraits<nsAString>
 {
   typedef nsLiteralString paramType;
 };
 
+template <>
+struct ParamTraits<nsDependentSubstring> : ParamTraits<nsAString>
+{
+  typedef nsDependentSubstring paramType;
+};
+
+template <>
+struct ParamTraits<nsDependentCSubstring> : ParamTraits<nsACString>
+{
+  typedef nsDependentCSubstring paramType;
+};
+
 #ifdef MOZILLA_INTERNAL_API
 
 template<>
 struct ParamTraits<nsAutoString> : ParamTraits<nsString>
 {
   typedef nsAutoString paramType;
 };
 
--- a/ipc/ipdl/ipdl/builtin.py
+++ b/ipc/ipdl/ipdl/builtin.py
@@ -31,16 +31,18 @@ Types = (
     # stddef types
     'size_t',
     'ssize_t',
 
     # Mozilla types: "less" standard things we know how serialize/deserialize
     'nsresult',
     'nsString',
     'nsCString',
+    'nsDependentSubstring',
+    'nsDependentCSubstring',
     'mozilla::ipc::Shmem',
     'mozilla::ipc::FileDescriptor'
 )
 
 
 HeaderIncludes = (
     'mozilla/Attributes.h',
     'IPCMessageStart.h',
--- a/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl
+++ b/netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl
@@ -31,17 +31,17 @@ parent:
              uint32_t      contentPolicyType);
   async AsyncOpen(URIParams             originalURI,
                   uint32_t              loadFlags,
                   SerializedLoadContext loadContext,
                   PBrowserOrId browser);
   async AppData(SerializedLoadContext loadContext, PBrowserOrId browser);
 
   // methods corresponding to those of nsIWyciwygChannel
-  async WriteToCacheEntry(nsString data);
+  async WriteToCacheEntry(nsDependentSubstring data);
   async CloseCacheEntry(nsresult reason);
   async SetCharsetAndSource(int32_t source, nsCString charset);
   async SetSecurityInfo(nsCString securityInfo);
   async Cancel(nsresult status);
 
 child:
   async OnStartRequest(nsresult  statusCode,
                        int64_t   contentLength,
--- a/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelChild.cpp
@@ -698,17 +698,17 @@ WyciwygChannelChild::WriteToCacheEntry(c
   // Give ourselves a megabyte of headroom for the message size. Convert bytes
   // to wide chars.
   static const size_t kMaxMessageSize = (IPC::Channel::kMaximumMessageSize - 1024) / 2;
 
   size_t curIndex = 0;
   size_t charsRemaining = aData.Length();
   do {
     size_t chunkSize = std::min(charsRemaining, kMaxMessageSize);
-    SendWriteToCacheEntry(PromiseFlatString(Substring(aData, curIndex, chunkSize)));
+    SendWriteToCacheEntry(Substring(aData, curIndex, chunkSize));
 
     charsRemaining -= chunkSize;
     curIndex += chunkSize;
   } while (charsRemaining != 0);
 
   return NS_OK;
 }
 
--- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.cpp
@@ -248,17 +248,17 @@ WyciwygChannelParent::RecvAsyncOpen(cons
     }
     return IPC_OK();
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
-WyciwygChannelParent::RecvWriteToCacheEntry(const nsString& data)
+WyciwygChannelParent::RecvWriteToCacheEntry(const nsDependentSubstring& data)
 {
   if (!mReceivedAppData) {
     printf_stderr("WyciwygChannelParent::RecvWriteToCacheEntry: FATAL ERROR: didn't receive app data\n");
     return IPC_FAIL_NO_REASON(this);
   }
 
   if (mChannel)
     mChannel->WriteToCacheEntry(data);
--- a/netwerk/protocol/wyciwyg/WyciwygChannelParent.h
+++ b/netwerk/protocol/wyciwyg/WyciwygChannelParent.h
@@ -40,17 +40,17 @@ protected:
                                            const ipc::PrincipalInfo& aTriggeringPrincipalInfo,
                                            const ipc::PrincipalInfo& aPrincipalToInheritInfo,
                                            const uint32_t&           aSecurityFlags,
                                            const uint32_t&           aContentPolicyType) override;
   virtual mozilla::ipc::IPCResult RecvAsyncOpen(const URIParams& original,
                                                 const uint32_t& loadFlags,
                                                 const IPC::SerializedLoadContext& loadContext,
                                                 const PBrowserOrId &parent) override;
-  virtual mozilla::ipc::IPCResult RecvWriteToCacheEntry(const nsString& data) override;
+  virtual mozilla::ipc::IPCResult RecvWriteToCacheEntry(const nsDependentSubstring& data) override;
   virtual mozilla::ipc::IPCResult RecvCloseCacheEntry(const nsresult& reason) override;
   virtual mozilla::ipc::IPCResult RecvSetCharsetAndSource(const int32_t& source,
                                                           const nsCString& charset) override;
   virtual mozilla::ipc::IPCResult RecvSetSecurityInfo(const nsCString& securityInfo) override;
   virtual mozilla::ipc::IPCResult RecvCancel(const nsresult& statusCode) override;
   virtual mozilla::ipc::IPCResult RecvAppData(const IPC::SerializedLoadContext& loadContext,
                                               const PBrowserOrId &parent) override;