From 4497dad959b2464197ce069beea0afd7ee38af8c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 8 Oct 2026 22:07:35 -1000 Subject: [PATCH] Keep the inline short string encode off ESP8266 --- esphome/components/api/proto.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 245032f83dc..189cee9e0eb 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -410,7 +410,7 @@ class ProtoEncode { [[nodiscard]] static inline uint8_t *encode_short_string_force(uint8_t *__restrict__ pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const StringRef &ref) { #ifdef USE_ESP8266 - // memcpy_P reads RAM too, so RAM strings share the outlined copy + // memcpy_P reads RAM too, so RAM strings share the progmem copy return encode_short_progmem_string_force(pos PROTO_ENCODE_DEBUG_ARG, tag, ProgmemStringRef(ref)); #else #ifdef ESPHOME_DEBUG_API @@ -424,7 +424,8 @@ class ProtoEncode { #endif } /// encode_short_string_force for a string that may be in flash (PROGMEM). - [[nodiscard]] static PROTO_OUTLINE_FOR_SIZE uint8_t *encode_short_progmem_string_force( +#ifdef USE_ESP8266 + [[nodiscard]] static inline uint8_t *encode_short_progmem_string_force( uint8_t *__restrict__ pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const ProgmemStringRef &ref) { #ifdef ESPHOME_DEBUG_API assert(ref.size() < 128 && "encode_short_progmem_string_force: string exceeds max_data_length < 128"); @@ -435,6 +436,12 @@ class ProtoEncode { progmem_memcpy(pos + 2, ref.progmem_ptr(), ref.size()); return pos + 2 + ref.size(); } +#else + [[nodiscard]] static inline uint8_t *encode_short_progmem_string_force( + uint8_t *__restrict__ pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const ProgmemStringRef &ref) { + return encode_short_string_force(pos PROTO_ENCODE_DEBUG_ARG, tag, ref.ram_ref()); + } +#endif /// Write a precomputed tag byte + 32-bit value. Outlined on embedded: one copy beats inline stores per field. [[nodiscard]] static PROTO_OUTLINE_FOR_SIZE uint8_t *write_tag_and_fixed32( uint8_t *__restrict__ pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, uint32_t value) {