Title: [292764] trunk/Source/WebKit
Revision
292764
Author
[email protected]
Date
2022-04-11 23:30:51 -0700 (Mon, 11 Apr 2022)

Log Message

[WK2] Simplify IPC encoding, decoding of tuples
https://bugs.webkit.org/show_bug.cgi?id=239062

Reviewed by Darin Adler.

For encoding each element of a given tuple, an index sequence is used in
combination with a fold _expression_ calling ArgumentCoder<T>::encode().

For decoding, std::tuple_cat() is used to concatenate a single-element
tuple containing the current element with the tuple of the remaining
decoded elements.

No real change in behavior, sequence of encoding and decoding remains
the same.

* Platform/IPC/ArgumentCoders.h:
(IPC::TupleEncoder::encode):
(IPC::tupleFromTupleAndObject): Deleted.
(IPC::TupleDecoderImpl::decode): Deleted.
(IPC::TupleDecoderImpl<Type>::decode): Deleted.
(IPC::TupleDecoder::decode): Deleted.
(IPC::TupleDecoder<0>::decode): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292763 => 292764)


--- trunk/Source/WebKit/ChangeLog	2022-04-12 06:10:33 UTC (rev 292763)
+++ trunk/Source/WebKit/ChangeLog	2022-04-12 06:30:51 UTC (rev 292764)
@@ -1,3 +1,28 @@
+2022-04-11  Zan Dobersek  <[email protected]>
+
+        [WK2] Simplify IPC encoding, decoding of tuples
+        https://bugs.webkit.org/show_bug.cgi?id=239062
+
+        Reviewed by Darin Adler.
+
+        For encoding each element of a given tuple, an index sequence is used in
+        combination with a fold _expression_ calling ArgumentCoder<T>::encode().
+
+        For decoding, std::tuple_cat() is used to concatenate a single-element
+        tuple containing the current element with the tuple of the remaining
+        decoded elements.
+
+        No real change in behavior, sequence of encoding and decoding remains
+        the same.
+
+        * Platform/IPC/ArgumentCoders.h:
+        (IPC::TupleEncoder::encode):
+        (IPC::tupleFromTupleAndObject): Deleted.
+        (IPC::TupleDecoderImpl::decode): Deleted.
+        (IPC::TupleDecoderImpl<Type>::decode): Deleted.
+        (IPC::TupleDecoder::decode): Deleted.
+        (IPC::TupleDecoder<0>::decode): Deleted.
+
 2022-04-11  Diego Pino Garcia  <[email protected]>
 
         [GLIB] Unreviewed, build fix for Debian Stable after r292251

Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h (292763 => 292764)


--- trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h	2022-04-12 06:10:33 UTC (rev 292763)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h	2022-04-12 06:30:51 UTC (rev 292764)
@@ -290,38 +290,26 @@
     }
 };
 
-template<size_t index, typename... Elements>
+template<typename... Elements>
 struct TupleEncoder {
     template<typename Encoder>
     static void encode(Encoder& encoder, const std::tuple<Elements...>& tuple)
     {
-        encoder << std::get<sizeof...(Elements) - index>(tuple);
-        TupleEncoder<index - 1, Elements...>::encode(encoder, tuple);
+        encode(encoder, tuple, std::index_sequence_for<Elements...> { });
     }
-};
 
-template<typename... Elements>
-struct TupleEncoder<0, Elements...> {
-    template<typename Encoder>
-    static void encode(Encoder&, const std::tuple<Elements...>&)
+    template<typename Encoder, size_t... Indices>
+    static void encode(Encoder& encoder, const std::tuple<Elements...>& tuple, std::index_sequence<Indices...>)
     {
+        if constexpr (sizeof...(Indices) > 0)
+            (encoder << ... << std::get<Indices>(tuple));
     }
 };
 
-template <typename T, typename... Elements, size_t... Indices>
-auto tupleFromTupleAndObject(T&& object, std::tuple<Elements...>&& tuple, std::index_sequence<Indices...>)
-{
-    return std::make_tuple(WTFMove(object), WTFMove(std::get<Indices>(tuple))...);
-}
+template<typename... Elements> struct TupleDecoder;
 
-template <typename T, typename... Elements>
-auto tupleFromTupleAndObject(T&& object, std::tuple<Elements...>&& tuple)
-{
-    return tupleFromTupleAndObject(WTFMove(object), WTFMove(tuple), std::index_sequence_for<Elements...>());
-}
-
 template<typename Type, typename... Types>
-struct TupleDecoderImpl {
+struct TupleDecoder<Type, Types...> {
     template<typename Decoder>
     static std::optional<std::tuple<Type, Types...>> decode(Decoder& decoder)
     {
@@ -330,38 +318,16 @@
         if (!optional)
             return std::nullopt;
 
-        std::optional<std::tuple<Types...>> subTuple = TupleDecoderImpl<Types...>::decode(decoder);
-        if (!subTuple)
+        std::optional<std::tuple<Types...>> remainder = TupleDecoder<Types...>::decode(decoder);
+        if (!remainder)
             return std::nullopt;
 
-        return tupleFromTupleAndObject(WTFMove(*optional), WTFMove(*subTuple));
+        return std::tuple_cat(std::make_tuple(WTFMove(*optional)), WTFMove(*remainder));
     }
 };
 
-template<typename Type>
-struct TupleDecoderImpl<Type> {
-    template<typename Decoder>
-    static std::optional<std::tuple<Type>> decode(Decoder& decoder)
-    {
-        std::optional<Type> optional;
-        decoder >> optional;
-        if (!optional)
-            return std::nullopt;
-        return std::make_tuple(WTFMove(*optional));
-    }
-};
-
-template<size_t size, typename... Elements>
-struct TupleDecoder {
-    template<typename Decoder>
-    static std::optional<std::tuple<Elements...>> decode(Decoder& decoder)
-    {
-        return TupleDecoderImpl<Elements...>::decode(decoder);
-    }
-};
-
 template<>
-struct TupleDecoder<0> {
+struct TupleDecoder<> {
     template<typename Decoder>
     static std::optional<std::tuple<>> decode(Decoder&)
     {
@@ -373,13 +339,13 @@
     template<typename Encoder>
     static void encode(Encoder& encoder, const std::tuple<Elements...>& tuple)
     {
-        TupleEncoder<sizeof...(Elements), Elements...>::encode(encoder, tuple);
+        TupleEncoder<Elements...>::encode(encoder, tuple);
     }
 
     template<typename Decoder>
     static std::optional<std::tuple<Elements...>> decode(Decoder& decoder)
     {
-        return TupleDecoder<sizeof...(Elements), Elements...>::decode(decoder);
+        return TupleDecoder<Elements...>::decode(decoder);
     }
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to