From 6feaa8dd1393deb2be259f65d04d2b98a0d85aed Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 9 Nov 2025 23:10:06 -0600 Subject: [PATCH] preserve order --- esphome/core/helpers.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 732a8a66af..4588c759e8 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -889,10 +889,11 @@ template class PartitionedCallbackManager { this->callbacks_ = make_unique>>(); } - // Add to first partition: append then swap into position + // Add to first partition: append then rotate into position this->callbacks_->push_back(std::move(callback)); if (*first_count < this->callbacks_->size() - 1) { - std::swap((*this->callbacks_)[*first_count], (*this->callbacks_)[this->callbacks_->size() - 1]); + // Use std::rotate to maintain registration order in second partition + std::rotate(this->callbacks_->begin() + *first_count, this->callbacks_->end() - 1, this->callbacks_->end()); } (*first_count)++; }