Replace std::bind calls in subscribe/subscribe_json template methods
with equivalent lambdas. Uses static_cast<T*>(this) instead of
C-style cast for type safety.
Replace std::bind calls in subscribe_homeassistant_state template
methods with equivalent lambdas. Uses static_cast<T*>(this) instead
of C-style cast for type safety.
Replace std::bind calls that use std::placeholders with equivalent
lambdas. Lambdas with explicit parameters are more readable and
generate smaller callable objects than std::bind results.
Components: wifi (libretiny), haier (base, hon, smartair2),
homeassistant/number.
The set_timeout lambda captured [this, curr_time_ns] (4 + 8 = 12
bytes), exceeding the std::function small buffer optimization
threshold (8 bytes on 32-bit) and forcing a heap allocation every
measurement cycle (every 3s in LP mode).
Store curr_time_ns as a class member and capture only [this] (4
bytes), which fits inline in the SBO. Trades 8 bytes of permanent
member storage to eliminate a heap alloc+free cycle per measurement.
Replace std::bind calls with [this] lambdas for add_on_time_sync_callback
and defer registrations. The [this] lambda fits within the Callback
inline storage threshold (sizeof(void*)), avoiding heap allocations.
Replace std::bind(&MultiClickTrigger::on_state_, this, _1) with a
[this] lambda for the add_on_state_callback registration. The [this]
lambda fits within the Callback inline storage threshold
(sizeof(void*)), avoiding a permanent heap allocation.
FixedVector requires init() before push_back(). Update all test cases
to call set_sensor_count()/set_binary_sensor_count() before adding
sensors, matching what the Python codegen does.
The lambdas are defined inside PacketTransport::setup() so they
inherit member-function access rights. The friend declarations
are not needed for accessing protected members through parent pointer.
The sensor and binary sensor counts are known at config time, so
pre-allocate with FixedVector::init() instead of using std::vector
which pulls in _M_realloc_insert template instantiation code.
The source count is known at config time, so pre-allocate with
FixedVector::init() instead of using std::vector which pulls in
_M_realloc_insert template instantiation code.
Replace std::pair<Sensor*, std::function> with a SensorSource struct
that includes a back-pointer to the parent component. This allows
KalmanCombinationComponent::setup() to capture only [&source] (one
pointer) instead of [this, stddev] (this + a full std::function copy),
enabling inline Callback storage and avoiding a heap allocation per
sensor callback registration.
Add a back-pointer to PacketTransport in the Sensor and BinarySensor
structs so the state callback lambdas can capture only [&sensor] (one
pointer) instead of [this, &sensor] (two pointers). This brings the
capture size within the Callback inline threshold (sizeof(void*)),
avoiding a heap allocation per callback registration.