mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 08:55:36 +00:00
[api] Outline ProtoByteBuffer reallocation into grow_()
The capacity check in reserve()/resize() is the hot path and stays inline via ESPHOME_ALWAYS_INLINE. The actual reallocation (make_buffer + memcpy) is a cold path outlined into grow_() to avoid bloating every call site. resize() delegates to reserve() for the capacity check since both inline to the same code.
This commit is contained in:
@@ -259,13 +259,12 @@ inline std::unique_ptr<uint8_t[]> make_buffer(size_t n) {
|
||||
class ProtoByteBuffer {
|
||||
public:
|
||||
void clear() { this->size_ = 0; }
|
||||
void reserve(size_t n) {
|
||||
inline void reserve(size_t n) ESPHOME_ALWAYS_INLINE {
|
||||
if (n > this->capacity_)
|
||||
this->grow_(n);
|
||||
}
|
||||
void resize(size_t n) {
|
||||
if (n > this->capacity_)
|
||||
this->grow_(n);
|
||||
inline void resize(size_t n) ESPHOME_ALWAYS_INLINE {
|
||||
this->reserve(n);
|
||||
this->size_ = n; // no zero-fill
|
||||
}
|
||||
uint8_t *data() { return this->data_.get(); }
|
||||
|
||||
Reference in New Issue
Block a user