summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/Rect.cpp
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-12-22 20:40:33 -0500
committerAndreas Kling <kling@serenityos.org>2022-12-26 09:36:16 +0100
commit9b483625e653d2ea89533c99b501a2e296c4d366 (patch)
treea84ddbd6a8bae04104dd9617e3b99e5e1f8e9c4a /Userland/Libraries/LibGfx/Rect.cpp
parent765c5b416f61f08dd68ea4b77a39e9380f2c8f9d (diff)
downloadserenity-9b483625e653d2ea89533c99b501a2e296c4d366.zip
LibIPC+Everywhere: Change IPC decoders to construct values in-place
Currently, the generated IPC decoders will default-construct the type to be decoded, then pass that value by reference to the concrete decoder. This, of course, requires that the type is default-constructible. This was an issue for decoding Variants, which had to require the first type in the Variant list is Empty, to ensure it is default constructible. Further, this made it possible for values to become uninitialized in user-defined decoders. This patch makes the decoder interface such that the concrete decoders themselves contruct the decoded type upon return from the decoder. To do so, the default decoders in IPC::Decoder had to be moved to the IPC namespace scope, as these decoders are now specializations instead of overloaded methods (C++ requires specializations to be in a namespace scope).
Diffstat (limited to 'Userland/Libraries/LibGfx/Rect.cpp')
-rw-r--r--Userland/Libraries/LibGfx/Rect.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/Userland/Libraries/LibGfx/Rect.cpp b/Userland/Libraries/LibGfx/Rect.cpp
index 6c85b50fac..68bbfd4ead 100644
--- a/Userland/Libraries/LibGfx/Rect.cpp
+++ b/Userland/Libraries/LibGfx/Rect.cpp
@@ -38,14 +38,11 @@ bool encode(Encoder& encoder, Gfx::IntRect const& rect)
}
template<>
-ErrorOr<void> decode(Decoder& decoder, Gfx::IntRect& rect)
+ErrorOr<Gfx::IntRect> decode(Decoder& decoder)
{
- Gfx::IntPoint point;
- Gfx::IntSize size;
- TRY(decoder.decode(point));
- TRY(decoder.decode(size));
- rect = { point, size };
- return {};
+ auto point = TRY(decoder.decode<Gfx::IntPoint>());
+ auto size = TRY(decoder.decode<Gfx::IntSize>());
+ return Gfx::IntRect { point, size };
}
}