Avoid using lambdas in Abseil assertion macros Lambdas are costlier at compile-time and run-time, as they are much heavier machinery and lean much more heavily on the optimizer. PiperOrigin-RevId: 888814590 Change-Id: I439a36eb6e5ad28fd16675bc254beb315172544c
diff --git a/absl/base/macros.h b/absl/base/macros.h index 446a445..d42ecf1 100644 --- a/absl/base/macros.h +++ b/absl/base/macros.h
@@ -108,18 +108,15 @@ #else #define ABSL_ASSERT(expr) \ (ABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \ - : [] { assert(false && #expr); }()) // NOLINT + : assert(false && #expr)) // NOLINT #endif // `ABSL_INTERNAL_HARDENING_ABORT()` controls how `ABSL_HARDENING_ASSERT()` // aborts the program in release mode (when NDEBUG is defined). The // implementation should abort the program as quickly as possible and ideally it // should not be possible to ignore the abort request. -#define ABSL_INTERNAL_HARDENING_ABORT() \ - do { \ - ABSL_INTERNAL_IMMEDIATE_ABORT_IMPL(); \ - ABSL_INTERNAL_UNREACHABLE_IMPL(); \ - } while (false) +#define ABSL_INTERNAL_HARDENING_ABORT() \ + ((void)ABSL_INTERNAL_IMMEDIATE_ABORT_IMPL(), ABSL_INTERNAL_UNREACHABLE_IMPL()) // ABSL_HARDENING_ASSERT() // @@ -135,7 +132,7 @@ #if (ABSL_OPTION_HARDENED == 1 || ABSL_OPTION_HARDENED == 2) && defined(NDEBUG) #define ABSL_HARDENING_ASSERT(expr) \ (ABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \ - : [] { ABSL_INTERNAL_HARDENING_ABORT(); }()) + : ABSL_INTERNAL_HARDENING_ABORT()) #else #define ABSL_HARDENING_ASSERT(expr) ABSL_ASSERT(expr) #endif @@ -154,7 +151,7 @@ #if ABSL_OPTION_HARDENED == 1 && defined(NDEBUG) #define ABSL_HARDENING_ASSERT_SLOW(expr) \ (ABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \ - : [] { ABSL_INTERNAL_HARDENING_ABORT(); }()) + : ABSL_INTERNAL_HARDENING_ABORT()) #else #define ABSL_HARDENING_ASSERT_SLOW(expr) ABSL_ASSERT(expr) #endif
diff --git a/absl/base/optimization.h b/absl/base/optimization.h index b561128..1fd32c5 100644 --- a/absl/base/optimization.h +++ b/absl/base/optimization.h
@@ -217,7 +217,7 @@ #elif defined(_MSC_VER) #define ABSL_INTERNAL_UNREACHABLE_IMPL() __assume(false) #else -#define ABSL_INTERNAL_UNREACHABLE_IMPL() +#define ABSL_INTERNAL_UNREACHABLE_IMPL() ((void)0) #endif // `ABSL_UNREACHABLE()` is an unreachable statement. A program which reaches