From 7cc139c3f7ea83f07a065369616ff0e56d0e0614 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 5 Dec 2022 13:35:33 +0100 Subject: [PATCH] Make expect and check use unlikely --- luna/include/luna/Check.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/luna/include/luna/Check.h b/luna/include/luna/Check.h index fce54b96..fe1c7f50 100644 --- a/luna/include/luna/Check.h +++ b/luna/include/luna/Check.h @@ -8,6 +8,18 @@ extern _noreturn bool __check_failed(const char* file, const char* line, const c #define STRINGIZE_VALUE_OF(x) STRINGIZE(x) #endif -#define check(expr) (expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr) #define expect(expr, message) \ - (expr) || __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message) + do { \ + if (!(expr)) [[unlikely]] \ + { \ + __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, message); \ + } \ + } while (0) + +#define check(expr) \ + do { \ + if (!(expr)) [[unlikely]] \ + { \ + __check_failed(__FILE__, STRINGIZE_VALUE_OF(__LINE__), __PRETTY_FUNCTION__, #expr); \ + } \ + } while (0)