From 475927e3c47409510bf6ab3bc75c51787fb81af9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 1 Apr 2026 10:08:24 -1000 Subject: [PATCH] =?UTF-8?q?[api]=20Revert=20add=5Fitem=5Ffront=20back=20to?= =?UTF-8?q?=20inline=20=E2=80=94=20single=20call=20site?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esphome/components/api/api_connection.cpp | 8 -------- esphome/components/api/api_connection.h | 9 +++++++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index a6e4e8bf9cd..c882d48112d 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -2072,14 +2072,6 @@ void APIConnection::on_fatal_error() { this->flags_.remove = true; } -void APIConnection::DeferredBatch::add_item_front(EntityBase *entity, uint8_t message_type, uint8_t estimated_size) { - // Swap to front avoids expensive vector::insert which shifts all elements - this->items.push_back({entity, message_type, estimated_size, AUX_DATA_UNUSED}); - if (this->items.size() > 1) { - std::swap(this->items.front(), this->items.back()); - } -} - bool APIConnection::send_message_smart_(EntityBase *entity, uint8_t message_type, uint8_t estimated_size, uint8_t aux_data_index) { if (this->should_send_immediately_(message_type) && this->helper_->can_write_without_blocking()) { diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index c39ae47bc9a..776b67738c9 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -659,8 +659,13 @@ class APIConnection final : public APIServerConnectionBase { this->items.push_back({entity, message_type, estimated_size, aux_data_index}); } // Add item to the front of the batch (for high priority messages like ping) - // Out-of-line: called from cold paths (on_shutdown, check_keepalive_) - void add_item_front(EntityBase *entity, uint8_t message_type, uint8_t estimated_size); + void add_item_front(EntityBase *entity, uint8_t message_type, uint8_t estimated_size) { + // Swap to front avoids expensive vector::insert which shifts all elements + this->items.push_back({entity, message_type, estimated_size, AUX_DATA_UNUSED}); + if (this->items.size() > 1) { + std::swap(this->items.front(), this->items.back()); + } + } // Clear all items void clear() {