mirror of
https://github.com/esphome/esphome.git
synced 2026-10-04 02:05:59 +00:00
[api] Outline ProtoByteBuffer reallocation into grow_()
The capacity check in reserve()/resize() is the hot path and stays inline. The actual reallocation (make_buffer + memcpy) is a cold path that should be outlined to avoid bloating every call site. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
d3c5d91469
commit
9e082edecb
@@ -8,6 +8,14 @@ namespace esphome::api {
|
||||
|
||||
static const char *const TAG = "api.proto";
|
||||
|
||||
void ProtoByteBuffer::grow_(size_t n) {
|
||||
auto new_data = make_buffer(n);
|
||||
if (this->size_)
|
||||
std::memcpy(new_data.get(), this->data_.get(), this->size_);
|
||||
this->data_ = std::move(new_data);
|
||||
this->capacity_ = n;
|
||||
}
|
||||
|
||||
#ifdef USE_API_VARINT64
|
||||
optional<ProtoVarInt> ProtoVarInt::parse_wide(const uint8_t *buffer, uint32_t len, uint32_t *consumed,
|
||||
uint32_t result32) {
|
||||
|
||||
Reference in New Issue
Block a user