[core] Address review nits

- Remove stale #include <functional> from microphone headers
- Add default initializers to Callback::fn and Callback::ctx
- Remove redundant cb.ctx = nullptr (now default-initialized)
This commit is contained in:
J. Nick Koston
2026-03-15 23:08:48 -10:00
parent 610258b683
commit 7edcc15cee
3 changed files with 3 additions and 6 deletions
@@ -4,7 +4,6 @@
#include <cstddef>
#include <cstdint>
#include <functional>
#include <vector>
#include "esphome/core/helpers.h"
@@ -7,7 +7,6 @@
#include <bitset>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <vector>
namespace esphome {
+3 -4
View File
@@ -1741,8 +1741,8 @@ template<typename... Ts> struct Callback<void(Ts...)> {
// This requires all bit patterns to be valid for void* (no trap representations).
static_assert(sizeof(void *) == sizeof(std::uintptr_t), "void* must be the same size as uintptr_t");
void (*fn)(void *, Ts...);
void *ctx;
void (*fn)(void *, Ts...){nullptr};
void *ctx{nullptr};
void call(Ts... args) const { this->fn(this->ctx, args...); }
@@ -1754,8 +1754,7 @@ template<typename... Ts> struct Callback<void(Ts...)> {
// Small trivial callable (e.g. [this]() { this->method(); }) - store inline in ctx.
// Safe under C++20 (P0593R6): byte copy into aligned storage implicitly
// creates objects of implicit-lifetime types (trivially copyable qualifies).
Callback cb;
cb.ctx = nullptr;
Callback cb; // fn and ctx are zero-initialized by default
__builtin_memcpy(&cb.ctx, &callable, sizeof(DecayF));
cb.fn = [](void *c, Ts... args) {
alignas(DecayF) char buf[sizeof(DecayF)];