diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2020-04-30 11:54:27 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-30 11:30:27 +0200 |
commit | 1b36ddce1d19b6d82bdfa6ebf39c311a4599a988 (patch) | |
tree | 144ef6d2a809c0e19f1e56a0c51dbe36bcb93fe6 /Libraries/LibC | |
parent | b319aca81a6d978bf8dc22aa2b40592ed6ed10a5 (diff) | |
download | serenity-1b36ddce1d19b6d82bdfa6ebf39c311a4599a988.zip |
LibC: Hint the compiler that assertions rarely fail
Also, rewrite the macro to expand to an if statement instead of
a weird ternary operator with a (void)0 banch.
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/assert.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Libraries/LibC/assert.h b/Libraries/LibC/assert.h index bc374e5e12..18711ac0e8 100644 --- a/Libraries/LibC/assert.h +++ b/Libraries/LibC/assert.h @@ -34,7 +34,11 @@ __BEGIN_DECLS __attribute__((noreturn)) void __assertion_failed(const char* msg); # define __stringify_helper(x) # x # define __stringify(x) __stringify_helper(x) -# define assert(expr) ((expr) ? (void)0 : __assertion_failed(# expr "\n" __FILE__ ":" __stringify(__LINE__))); +# define assert(expr) \ + do { \ + if (__builtin_expect(!(expr), 0)) \ + __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)); \ + } while (0) # define ASSERT_NOT_REACHED() assert(false) #else # define assert(expr) |