From fdda6a5f5f65c7d1d7b5caa4b53f653fee6663f2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 25 Feb 2026 09:56:28 -0700 Subject: [PATCH] [api] Prefer make_unique_for_overwrite for noninit send buffers Use C++20 std::make_unique_for_overwrite instead of std::make_unique for the send buffer allocation in buffer_data_from_iov_. This skips the unnecessary zero-initialization for POD types, since the buffer is immediately and completely filled via memcpy from the iov segments in the loop that follows. --- esphome/components/api/api_frame_helper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index e432a976b0..ca51ab49d8 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -134,7 +134,7 @@ void APIFrameHelper::buffer_data_from_iov_(const struct iovec *iov, int iovcnt, uint16_t buffer_size = total_write_len - offset; auto &buffer = this->tx_buf_[this->tx_buf_tail_]; buffer = std::make_unique(SendBuffer{ - .data = std::make_unique(buffer_size), + .data = std::make_unique_for_overwrite(buffer_size), .size = buffer_size, .offset = 0, });