serenity/AK/Try.h
Idan Horowitz 8a879e205b AK: Mark the error branch of the TRY() macro as unlikely
This results in a measurable (and free!) 2% improvement in test-js
run time.
2022-01-16 02:01:23 +02:00

26 lines
866 B
C

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
// NOTE: This macro works with any result type that has the expected APIs.
// It's designed with AK::Result and AK::Error in mind.
#define TRY(expression) \
({ \
auto _temporary_result = (expression); \
if (_temporary_result.is_error()) [[unlikely]] \
return _temporary_result.release_error(); \
_temporary_result.release_value(); \
})
#define MUST(expression) \
({ \
auto _temporary_result = (expression); \
VERIFY(!_temporary_result.is_error()); \
_temporary_result.release_value(); \
})