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 /Userland/Libraries/LibAudio | |
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 'Userland/Libraries/LibAudio')
-rw-r--r-- | Userland/Libraries/LibAudio/LoaderError.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Userland/Libraries/LibAudio/LoaderError.h b/Userland/Libraries/LibAudio/LoaderError.h index a54a048902..9f31b6afad 100644 --- a/Userland/Libraries/LibAudio/LoaderError.h +++ b/Userland/Libraries/LibAudio/LoaderError.h @@ -68,7 +68,7 @@ struct LoaderError { // Convenience TRY-like macro to convert an Error to a LoaderError #define LOADER_TRY(expression) \ ({ \ - auto _temporary_result = (expression); \ + auto&& _temporary_result = (expression); \ if (_temporary_result.is_error()) \ return LoaderError(_temporary_result.release_error()); \ static_assert(!::AK::Detail::IsLvalueReference<decltype(_temporary_result.release_value())>, \ |