From 5b5388b3ff13594fc66030ba1c12ce8c66b49791 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 28 Oct 2025 21:58:36 -0500 Subject: [PATCH] likely --- esphome/components/api/proto.h | 8 +------- esphome/core/macros.h | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 055498c4a6..f68ef330f6 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -3,6 +3,7 @@ #include "esphome/core/component.h" #include "esphome/core/helpers.h" #include "esphome/core/log.h" +#include "esphome/core/macros.h" #include "esphome/core/string_ref.h" #include @@ -14,13 +15,6 @@ #define HAS_PROTO_MESSAGE_DUMP #endif -// Branch prediction hints for hot paths -#if defined(__GNUC__) || defined(__clang__) -#define ESPHOME_LIKELY(x) __builtin_expect(!!(x), 1) -#else -#define ESPHOME_LIKELY(x) (x) -#endif - namespace esphome::api { // Protocol Buffer wire type constants diff --git a/esphome/core/macros.h b/esphome/core/macros.h index 8b2383321b..79878ce714 100644 --- a/esphome/core/macros.h +++ b/esphome/core/macros.h @@ -3,6 +3,15 @@ // Helper macro to define a version code, whose value can be compared against other version codes. #define VERSION_CODE(major, minor, patch) ((major) << 16 | (minor) << 8 | (patch)) +// Branch prediction hints for performance-critical paths +#if defined(__GNUC__) || defined(__clang__) +#define ESPHOME_LIKELY(x) __builtin_expect(!!(x), 1) +#define ESPHOME_UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define ESPHOME_LIKELY(x) (x) +#define ESPHOME_UNLIKELY(x) (x) +#endif + #ifdef USE_ARDUINO #include #endif