From f57468109bf81e2425abfbdd512c3b190533a920 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 12:14:54 -1000 Subject: [PATCH] [api] Split write_raw_fast_ into write_raw_fast_buf_ and write_raw_fast_iov_ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No overloads — every method has a unique name matching its data type: write_raw_fast_buf_ / write_raw_buf_ — single contiguous buffer write_raw_fast_iov_ / write_raw_iov_ — iovec array --- esphome/components/api/api_frame_helper.h | 5 +++-- esphome/components/api/api_frame_helper_noise.cpp | 4 ++-- esphome/components/api/api_frame_helper_plaintext.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/api/api_frame_helper.h b/esphome/components/api/api_frame_helper.h index cc5c6ee569..94007eeb3d 100644 --- a/esphome/components/api/api_frame_helper.h +++ b/esphome/components/api/api_frame_helper.h @@ -195,7 +195,7 @@ class APIFrameHelper { // Inlined write methods — used by hot paths (write_protobuf_packet, write_protobuf_messages) // These inline the fast path (overflow empty + full write) and tail-call the out-of-line // slow path only on failure/partial write. - inline APIError ESPHOME_ALWAYS_INLINE write_raw_fast_(const void *data, uint16_t len) { + inline APIError ESPHOME_ALWAYS_INLINE write_raw_fast_buf_(const void *data, uint16_t len) { ssize_t sent = -1; if (this->overflow_buf_.empty()) [[likely]] { sent = this->socket_->write(data, len); @@ -204,7 +204,8 @@ class APIFrameHelper { } return this->write_raw_buf_(data, len, sent); } - inline APIError ESPHOME_ALWAYS_INLINE write_raw_fast_(const struct iovec *iov, int iovcnt, uint16_t total_write_len) { + inline APIError ESPHOME_ALWAYS_INLINE write_raw_fast_iov_(const struct iovec *iov, int iovcnt, + uint16_t total_write_len) { ssize_t sent = -1; if (this->overflow_buf_.empty()) [[likely]] { sent = this->socket_->writev(iov, iovcnt); diff --git a/esphome/components/api/api_frame_helper_noise.cpp b/esphome/components/api/api_frame_helper_noise.cpp index 424f450fd9..0c0c069b53 100644 --- a/esphome/components/api/api_frame_helper_noise.cpp +++ b/esphome/components/api/api_frame_helper_noise.cpp @@ -504,7 +504,7 @@ APIError APINoiseFrameHelper::write_protobuf_packet(uint8_t type, ProtoWriteBuff APIError aerr = this->encrypt_noise_message_(buf_start, msg, iov); if (aerr != APIError::OK) return aerr; - return this->write_raw_fast_(iov.iov_base, static_cast(iov.iov_len)); + return this->write_raw_fast_buf_(iov.iov_base, static_cast(iov.iov_len)); } APIError APINoiseFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, std::span messages) { @@ -527,7 +527,7 @@ APIError APINoiseFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, s total_write_len += iov.iov_len; } - return this->write_raw_fast_(iovs.data(), iovs.size(), total_write_len); + return this->write_raw_fast_iov_(iovs.data(), iovs.size(), total_write_len); } APIError APINoiseFrameHelper::write_frame_(const uint8_t *data, uint16_t len) { diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index 1d2ea5bcb8..6be20f89f3 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -292,7 +292,7 @@ APIError APIPlaintextFrameHelper::write_protobuf_packet(uint8_t type, ProtoWrite uint8_t *msg_start = write_plaintext_header(buffer_data, msg, frame_header_padding_); uint8_t msg_header_len = static_cast(buffer_data + frame_header_padding_ - msg_start); uint16_t msg_len = static_cast(msg_header_len + msg.payload_size); - return this->write_raw_fast_(msg_start, msg_len); + return this->write_raw_fast_buf_(msg_start, msg_len); } APIError APIPlaintextFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, @@ -315,7 +315,7 @@ APIError APIPlaintextFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffe total_write_len += msg_len; } - return this->write_raw_fast_(iovs.data(), iovs.size(), total_write_len); + return this->write_raw_fast_iov_(iovs.data(), iovs.size(), total_write_len); } } // namespace esphome::api