diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-02-09 13:27:43 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-10 09:08:52 +0000 |
commit | 604d5f5bcae5f89778acf416334a823bcb114402 (patch) | |
tree | 46b56a3ede6c89c31e609c79b396d9e2c2f28e1f /Kernel | |
parent | 4a916cd3796cef0ef10374fcf9a602c96e226e6c (diff) | |
download | serenity-604d5f5bcae5f89778acf416334a823bcb114402.zip |
AK+Everywhere: Do not implicitly copy variables in TRY macros
For example, consider cases where we want to propagate errors only in
specific instances:
auto result = read_data(); // something like ErrorOr<ByteBuffer>
if (result.is_error() && result.error().code() != EINTR)
continue;
auto bytes = TRY(result);
The TRY invocation will currently copy the byte buffer when the
expression (in this case, just a local variable) is stored into
_temporary_result.
This patch binds the expression to a reference to prevent such copies.
In less trival invocations (such as TRY(some_function()), this will
incur only temporary lifetime extensions, i.e. no functional change.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/Net/Socket.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index 2599b3d6db..182a06bc5b 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -188,7 +188,7 @@ private: // This is a special variant of TRY() that also updates the socket's SO_ERROR field on error. #define SOCKET_TRY(expression) \ ({ \ - auto result = (expression); \ + auto&& result = (expression); \ if (result.is_error()) \ return set_so_error(result.release_error()); \ static_assert(!::AK::Detail::IsLvalueReference<decltype(result.release_value())>, \ |