[libcxx-commits] [PATCH] D122397: [libc++] Use __builtin_expect in _LIBCPP_ASSERT
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Mar 24 06:27:42 PDT 2022
ldionne created this revision.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
Since we expect the condition to be true most of the time, we might
as well tell the compiler.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122397
Files:
libcxx/include/__assert
Index: libcxx/include/__assert
===================================================================
--- libcxx/include/__assert
+++ libcxx/include/__assert
@@ -34,7 +34,10 @@
#endif
#if _LIBCPP_ENABLE_ASSERTIONS
-# define _LIBCPP_ASSERT(expression, message) ((expression) ? (void)0 : ::std::__libcpp_assertion_handler(__FILE__, __LINE__, #expression, message))
+# define _LIBCPP_ASSERT(expression, message) \
+ (__builtin_expect(static_cast<bool>(expression), 1) ? \
+ (void)0 : \
+ ::std::__libcpp_assertion_handler(__FILE__, __LINE__, #expression, message))
#else
# define _LIBCPP_ASSERT(x, m) ((void)0)
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122397.417907.patch
Type: text/x-patch
Size: 765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220324/60ca4843/attachment-0001.bin>
More information about the libcxx-commits
mailing list