mirror of
https://github.com/esphome/esphome.git
synced 2026-02-26 05:53:12 -07:00
[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.
This commit is contained in:
@@ -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>(SendBuffer{
|
||||
.data = std::make_unique<uint8_t[]>(buffer_size),
|
||||
.data = std::make_unique_for_overwrite<uint8_t[]>(buffer_size),
|
||||
.size = buffer_size,
|
||||
.offset = 0,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user