From a84d36cb37d24e2a212f32f5c2ee30fd3efb450a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 14:18:01 -1000 Subject: [PATCH] preen --- esphome/components/api/api_frame_helper.cpp | 3 +-- esphome/components/api/api_frame_helper.h | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 7beabdcac3..b8e65e655c 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -131,8 +131,7 @@ APIError APIFrameHelper::write_raw_iov_(const struct iovec *iov, int iovcnt, uin return err; } if (this->overflow_buf_.empty()) { - sent = - (iovcnt == 1) ? this->socket_->write(iov[0].iov_base, iov[0].iov_len) : this->socket_->writev(iov, iovcnt); + sent = this->write_iov_to_socket_(iov, iovcnt); if (sent == static_cast(total_write_len)) return APIError::OK; // Partial write or -1: fall through to error check / enqueue below diff --git a/esphome/components/api/api_frame_helper.h b/esphome/components/api/api_frame_helper.h index 812e360ea7..9c0f072e3b 100644 --- a/esphome/components/api/api_frame_helper.h +++ b/esphome/components/api/api_frame_helper.h @@ -196,6 +196,11 @@ class APIFrameHelper { static constexpr ssize_t WRITE_FAILED = -1; // Fast path: write()/writev() returned -1 static constexpr ssize_t WRITE_NOT_ATTEMPTED = -2; // Cold path: no write attempted yet + // Dispatch to write() or writev() based on iovec count + inline ssize_t ESPHOME_ALWAYS_INLINE write_iov_to_socket_(const struct iovec *iov, int iovcnt) { + return (iovcnt == 1) ? this->socket_->write(iov[0].iov_base, iov[0].iov_len) : this->socket_->writev(iov, iovcnt); + } + // 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.