From 7edcc15cee08f3bd42f511a48bbdf9d31ca053ea Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 15 Mar 2026 23:08:48 -1000 Subject: [PATCH] [core] Address review nits - Remove stale #include from microphone headers - Add default initializers to Callback::fn and Callback::ctx - Remove redundant cb.ctx = nullptr (now default-initialized) --- esphome/components/microphone/microphone.h | 1 - esphome/components/microphone/microphone_source.h | 1 - esphome/core/helpers.h | 7 +++---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/esphome/components/microphone/microphone.h b/esphome/components/microphone/microphone.h index f7093d3699..50ce1a7281 100644 --- a/esphome/components/microphone/microphone.h +++ b/esphome/components/microphone/microphone.h @@ -4,7 +4,6 @@ #include #include -#include #include #include "esphome/core/helpers.h" diff --git a/esphome/components/microphone/microphone_source.h b/esphome/components/microphone/microphone_source.h index 8947369376..5c8053e502 100644 --- a/esphome/components/microphone/microphone_source.h +++ b/esphome/components/microphone/microphone_source.h @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace esphome { diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index a8957db0b5..d9cad6954a 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -1741,8 +1741,8 @@ template struct Callback { // 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 struct Callback { // 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)];