From 8464045a38b98de96e96278759d121efd89c631b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 24 Nov 2023 07:50:00 -0600 Subject: [PATCH] Speed up writing protobuf strings/bytes --- esphome/components/api/proto.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index fea219ecb..ccc6c0d52 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -160,8 +160,7 @@ class ProtoWriteBuffer { this->encode_field_raw(field_id, 2); this->encode_varint_raw(len); auto *data = reinterpret_cast(string); - for (size_t i = 0; i < len; i++) - this->write(data[i]); + this->buffer_->insert(this->buffer_->end(), data, data + len); } void encode_string(uint32_t field_id, const std::string &value, bool force = false) { this->encode_string(field_id, value.data(), value.size());