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/LibVideo/PlaybackManager.cpp | |
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/LibVideo/PlaybackManager.cpp')
-rw-r--r-- | Userland/Libraries/LibVideo/PlaybackManager.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Userland/Libraries/LibVideo/PlaybackManager.cpp b/Userland/Libraries/LibVideo/PlaybackManager.cpp index b3953a01a0..0024fd4a0f 100644 --- a/Userland/Libraries/LibVideo/PlaybackManager.cpp +++ b/Userland/Libraries/LibVideo/PlaybackManager.cpp @@ -15,7 +15,7 @@ namespace Video { #define TRY_OR_FATAL_ERROR(expression) \ ({ \ - auto _fatal_expression = (expression); \ + auto&& _fatal_expression = (expression); \ if (_fatal_expression.is_error()) { \ dispatch_fatal_error(_fatal_expression.release_error()); \ return; \ @@ -156,7 +156,7 @@ bool PlaybackManager::decode_and_queue_one_sample() #define TRY_OR_ENQUEUE_ERROR(expression) \ ({ \ - auto _temporary_result = ((expression)); \ + auto&& _temporary_result = ((expression)); \ if (_temporary_result.is_error()) { \ dbgln_if(PLAYBACK_MANAGER_DEBUG, "Enqueued decoder error: {}", _temporary_result.error().string_literal()); \ m_frame_queue->enqueue(FrameQueueItem::error_marker(_temporary_result.release_error())); \ |