[api] Split write_raw_fast_ into write_raw_fast_buf_ and write_raw_fast_iov_

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
This commit is contained in:
J. Nick Koston
2026-03-29 12:14:54 -10:00
parent 048636d6c3
commit f57468109b
3 changed files with 7 additions and 6 deletions
+3 -2
View File
@@ -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);
@@ -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<uint16_t>(iov.iov_len));
return this->write_raw_fast_buf_(iov.iov_base, static_cast<uint16_t>(iov.iov_len));
}
APIError APINoiseFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, std::span<const MessageInfo> 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) {
@@ -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<uint8_t>(buffer_data + frame_header_padding_ - msg_start);
uint16_t msg_len = static_cast<uint16_t>(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