Bug 1525866 - Add IPDLParamTraits<Tuple<Ts...>>. r=froydnj
authorAndreas Farre <farre@mozilla.com>
Wed, 13 Feb 2019 16:08:03 +0000
changeset 459133 f830ab8c7d66cbf2e88280df4b21ad06cad27153
parent 459132 9a3d155d6e41743ee32331a226b8466c4748da04
child 459134 14f7c02566c263ddab470a3b2fa3f4b94fb6e181
push id35556
push userdvarga@mozilla.com
push dateFri, 15 Feb 2019 01:38:24 +0000
treeherdermozilla-central@b29c87add05f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1525866
milestone67.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 1525866 - Add IPDLParamTraits<Tuple<Ts...>>. r=froydnj Add support for serializing/deserializing tuples. Differential Revision: https://phabricator.services.mozilla.com/D18939
ipc/glue/IPDLParamTraits.h
netwerk/protocol/http/PHttpChannelParams.h
--- a/ipc/glue/IPDLParamTraits.h
+++ b/ipc/glue/IPDLParamTraits.h
@@ -65,16 +65,37 @@ static MOZ_NEVER_INLINE void WriteIPDLPa
 template <typename P>
 static MOZ_NEVER_INLINE bool ReadIPDLParam(const IPC::Message* aMsg,
                                            PickleIterator* aIter,
                                            IProtocol* aActor, P* aResult) {
   return IPDLParamTraits<typename IPC::ParamTraitsSelector<P>::Type>::Read(
       aMsg, aIter, aActor, aResult);
 }
 
+constexpr void WriteIPDLParamList(IPC::Message*, IProtocol*) {}
+
+template <typename P, typename... Ps>
+static void WriteIPDLParamList(IPC::Message* aMsg, IProtocol* aActor,
+                               const P& aParam, const Ps&... aParams) {
+  WriteIPDLParam(aMsg, aActor, aParam);
+  WriteIPDLParamList(aMsg, aActor, aParams...);
+}
+
+constexpr bool ReadIPDLParamList(const IPC::Message*, PickleIterator*,
+                                 IProtocol*) {
+  return true;
+}
+
+template <typename P, typename... Ps>
+static bool ReadIPDLParamList(const IPC::Message* aMsg, PickleIterator* aIter,
+                              IProtocol* aActor, P* aResult, Ps*... aResults) {
+  return ReadIPDLParam(aMsg, aIter, aActor, aResult) &&
+         ReadIPDLParamList(aMsg, aIter, aActor, aResults...);
+}
+
 // nsTArray support for IPDLParamTraits
 template <typename T>
 struct IPDLParamTraits<nsTArray<T>> {
   static inline void Write(IPC::Message* aMsg, IProtocol* aActor,
                            const nsTArray<T>& aParam) {
     WriteInternal(aMsg, aActor, aParam);
   }
 
@@ -188,12 +209,41 @@ struct IPDLParamTraits<mozilla::UniquePt
       delete obj;
       return false;
     }
     aResult->reset(obj);
     return true;
   }
 };
 
+template <typename... Ts>
+struct IPDLParamTraits<Tuple<Ts...>> {
+  static void Write(IPC::Message* aMsg, IProtocol* aActor,
+                    const Tuple<Ts...>& aParam) {
+    WriteInternal(aMsg, aActor, aParam, std::index_sequence_for<Ts...>{});
+  }
+
+  static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, Tuple<Ts...>* aResult) {
+    return ReadInternal(aMsg, aIter, aActor, *aResult,
+                        std::index_sequence_for<Ts...>{});
+  }
+
+ private:
+  template <size_t... Is>
+  static void WriteInternal(IPC::Message* aMsg, IProtocol* aActor,
+                            const Tuple<Ts...>& aParam,
+                            std::index_sequence<Is...>) {
+    WriteIPDLParamList(aMsg, aActor, Get<Is>(aParam)...);
+  }
+
+  template <size_t... Is>
+  static bool ReadInternal(const IPC::Message* aMsg, PickleIterator* aIter,
+                           IProtocol* aActor, Tuple<Ts...>& aResult,
+                           std::index_sequence<Is...>) {
+    return ReadIPDLParamList(aMsg, aIter, aActor, &Get<Is>(aResult)...);
+  }
+};
+
 }  // namespace ipc
 }  // namespace mozilla
 
 #endif  // defined(mozilla_ipc_IPDLParamTraits_h)
--- a/netwerk/protocol/http/PHttpChannelParams.h
+++ b/netwerk/protocol/http/PHttpChannelParams.h
@@ -38,37 +38,16 @@ typedef nsTArray<RequestHeaderTuple> Req
 typedef nsTArray<Tuple<nsCString, nsCString>> ArrayOfStringPairs;
 
 }  // namespace net
 }  // namespace mozilla
 
 namespace IPC {
 
 template <>
-struct ParamTraits<mozilla::Tuple<nsCString, nsCString>> {
-  typedef mozilla::Tuple<nsCString, nsCString> paramType;
-
-  static void Write(Message* aMsg, const paramType& aParam) {
-    WriteParam(aMsg, mozilla::Get<0>(aParam));
-    WriteParam(aMsg, mozilla::Get<1>(aParam));
-  }
-
-  static bool Read(const Message* aMsg, PickleIterator* aIter,
-                   paramType* aResult) {
-    nsCString first;
-    nsCString second;
-    if (!ReadParam(aMsg, aIter, &first) || !ReadParam(aMsg, aIter, &second))
-      return false;
-
-    *aResult = mozilla::MakeTuple(first, second);
-    return true;
-  }
-};
-
-template <>
 struct ParamTraits<mozilla::net::RequestHeaderTuple> {
   typedef mozilla::net::RequestHeaderTuple paramType;
 
   static void Write(Message* aMsg, const paramType& aParam) {
     WriteParam(aMsg, aParam.mHeader);
     WriteParam(aMsg, aParam.mValue);
     WriteParam(aMsg, aParam.mMerge);
     WriteParam(aMsg, aParam.mEmpty);