mirror of
https://github.com/esphome/esphome.git
synced 2025-11-01 15:41:52 +00:00
likely
This commit is contained in:
@@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
// Branch prediction hints for performance-critical paths
|
// Branch prediction hints for performance-critical paths
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
|
// GCC and Clang: use __builtin_expect for better optimization
|
||||||
#define ESPHOME_LIKELY(x) __builtin_expect(!!(x), 1)
|
#define ESPHOME_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||||
#define ESPHOME_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
#define ESPHOME_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||||
#else
|
#else
|
||||||
#define ESPHOME_LIKELY(x) (x)
|
// Other C++20 compilers: use standard attributes
|
||||||
#define ESPHOME_UNLIKELY(x) (x)
|
#define ESPHOME_LIKELY(x) (x) [[likely]]
|
||||||
|
#define ESPHOME_UNLIKELY(x) (x) [[unlikely]]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_ARDUINO
|
#ifdef USE_ARDUINO
|
||||||
|
|||||||
Reference in New Issue
Block a user