From cf33a61e3378775b7ec2d52f93837559eea775b9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 2 Feb 2026 03:08:01 +0100 Subject: [PATCH] avoid extra heap allocation, its unconditionally allocated anyways --- esphome/components/ethernet/ethernet_component.cpp | 6 +++--- esphome/components/ethernet/ethernet_component.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index db72fcc38b..af7fed608b 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -310,7 +310,7 @@ void EthernetComponent::loop() { this->dump_connect_params_(); this->status_clear_warning(); #ifdef USE_ETHERNET_CONNECT_TRIGGER - this->connect_trigger_->trigger(); + this->connect_trigger_.trigger(); #endif } else if (now - this->connect_begin_ > 15000) { ESP_LOGW(TAG, "Connecting failed; reconnecting"); @@ -322,14 +322,14 @@ void EthernetComponent::loop() { ESP_LOGI(TAG, "Stopped connection"); this->state_ = EthernetComponentState::STOPPED; #ifdef USE_ETHERNET_DISCONNECT_TRIGGER - this->disconnect_trigger_->trigger(); + this->disconnect_trigger_.trigger(); #endif } else if (!this->connected_) { ESP_LOGW(TAG, "Connection lost; reconnecting"); this->state_ = EthernetComponentState::CONNECTING; this->start_connect_(); #ifdef USE_ETHERNET_DISCONNECT_TRIGGER - this->disconnect_trigger_->trigger(); + this->disconnect_trigger_.trigger(); #endif } else { this->finish_connect_(); diff --git a/esphome/components/ethernet/ethernet_component.h b/esphome/components/ethernet/ethernet_component.h index 29712b3cee..5a2869c5a7 100644 --- a/esphome/components/ethernet/ethernet_component.h +++ b/esphome/components/ethernet/ethernet_component.h @@ -121,10 +121,10 @@ class EthernetComponent : public Component { #endif #ifdef USE_ETHERNET_CONNECT_TRIGGER - Trigger<> *get_connect_trigger() const { return this->connect_trigger_; } + Trigger<> *get_connect_trigger() { return &this->connect_trigger_; } #endif #ifdef USE_ETHERNET_DISCONNECT_TRIGGER - Trigger<> *get_disconnect_trigger() const { return this->disconnect_trigger_; } + Trigger<> *get_disconnect_trigger() { return &this->disconnect_trigger_; } #endif protected: static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); @@ -198,10 +198,10 @@ class EthernetComponent : public Component { #endif #ifdef USE_ETHERNET_CONNECT_TRIGGER - Trigger<> *connect_trigger_{new Trigger<>()}; + Trigger<> connect_trigger_; #endif #ifdef USE_ETHERNET_DISCONNECT_TRIGGER - Trigger<> *disconnect_trigger_{new Trigger<>()}; + Trigger<> disconnect_trigger_; #endif private: // Stores a pointer to a string literal (static storage duration).