From f0e3b992cfd5c750d72bdd175d62bdd9ebf8f9fa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 6 Apr 2026 08:51:42 -1000 Subject: [PATCH] Use indexed writes in write_short_string Single pointer advance instead of repeated post-increments. --- esphome/components/api/proto.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 643fa6bec0..2438b9355c 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -362,10 +362,10 @@ class ProtoEncode { static inline void ESPHOME_ALWAYS_INLINE write_short_string(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM, uint8_t tag, const StringRef &ref) { PROTO_ENCODE_CHECK_BOUNDS(pos, 2 + ref.size()); - *pos++ = tag; - *pos++ = static_cast(ref.size()); - std::memcpy(pos, ref.c_str(), ref.size()); - pos += ref.size(); + pos[0] = tag; + pos[1] = static_cast(ref.size()); + std::memcpy(pos + 2, ref.c_str(), ref.size()); + pos += 2 + ref.size(); } /// Write a precomputed tag byte + 32-bit value in one operation. static inline void ESPHOME_ALWAYS_INLINE write_tag_and_fixed32(uint8_t *__restrict__ &pos PROTO_ENCODE_DEBUG_PARAM,