1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 17:27:34 +00:00

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.
This commit is contained in:
Timothy Flynn 2023-02-09 13:27:43 -05:00 committed by Linus Groh
parent 4a916cd379
commit 604d5f5bca
11 changed files with 15 additions and 15 deletions

View file

@ -79,7 +79,7 @@ private:
#define DECODER_TRY(category, expression) \
({ \
auto _result = ((expression)); \
auto&& _result = ((expression)); \
if (_result.is_error()) [[unlikely]] { \
auto _error_string = _result.release_error().string_literal(); \
return DecoderError::from_source_location( \