From 25a68e9339e9cde478df7db195d6c40b6e59292c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 7 Mar 2026 08:22:09 -1000 Subject: [PATCH] [api] Inline capacity check in ProtoByteBuffer::resize() Avoid calling reserve() when capacity is already sufficient. After warmup, resize() becomes just a compare + store with no function call overhead on the hot path. --- esphome/components/api/proto.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 48e5497e811..845c614e3cd 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -262,7 +262,8 @@ class ProtoByteBuffer { } } void resize(size_t n) { - this->reserve(n); + if (n > this->capacity_) + this->reserve(n); this->size_ = n; // no zero-fill } uint8_t *data() { return this->data_.get(); }