mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:47:35 +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:
parent
4a916cd379
commit
604d5f5bca
11 changed files with 15 additions and 15 deletions
|
@ -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())); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue