mirror of
https://github.com/esphome/esphome.git
synced 2026-09-04 03:56:04 +00:00
[core] Skip zero-initialization of StaticVector data array
Remove value-initialization ({}) from StaticVector's underlying
std::array. Only elements [0, count_) are ever accessed, so
initializing the full array is wasted work.
This eliminates a memset on every construction. Most impactful for
stack-allocated StaticVectors in hot paths like
APIPlaintextFrameHelper::write_protobuf_messages, which was
memsetting 276 bytes of iovec storage on every BLE proxy flush.
This commit is contained in:
@@ -215,7 +215,7 @@ template<typename T, size_t N> class StaticVector {
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
private:
|
||||
std::array<T, N> data_{};
|
||||
std::array<T, N> data_; // intentionally not value-initialized to avoid memset
|
||||
size_t count_{0};
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user