mirror of
https://github.com/esphome/esphome.git
synced 2025-09-07 05:42:20 +01:00
merge
This commit is contained in:
@@ -272,28 +272,6 @@ void Application::teardown_components(uint32_t timeout_ms) {
|
|||||||
uint32_t now = start_time;
|
uint32_t now = start_time;
|
||||||
size_t pending_count = num_components;
|
size_t pending_count = num_components;
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
// Compaction algorithm for teardown
|
|
||||||
// ==================================
|
|
||||||
// We repeatedly call teardown() on each component until it returns true.
|
|
||||||
// Components that are done are removed using array compaction:
|
|
||||||
//
|
|
||||||
// Initial state (all components pending):
|
|
||||||
// pending_components: [A, B, C, D, E, F]
|
|
||||||
// pending_count: 6 ^
|
|
||||||
//
|
|
||||||
// After first iteration (B and D finish teardown):
|
|
||||||
// pending_components: [A, C, E, F | B, D] (B, D are still in memory but ignored)
|
|
||||||
// pending_count: 4 ^
|
|
||||||
//
|
|
||||||
// After second iteration (A finishes):
|
|
||||||
// pending_components: [C, E, F | A, B, D]
|
|
||||||
// pending_count: 3 ^
|
|
||||||
//
|
|
||||||
// The algorithm compacts remaining components to the front of the array,
|
|
||||||
// tracking only the count of pending components. This avoids expensive
|
|
||||||
// erase operations while maintaining O(n) complexity per iteration.
|
|
||||||
=======
|
|
||||||
// Teardown Algorithm
|
// Teardown Algorithm
|
||||||
// ==================
|
// ==================
|
||||||
// We iterate through pending components, calling teardown() on each.
|
// We iterate through pending components, calling teardown() on each.
|
||||||
@@ -330,7 +308,6 @@ void Application::teardown_components(uint32_t timeout_ms) {
|
|||||||
// After iteration 2:
|
// After iteration 2:
|
||||||
// pending_components: [C | C, D, D] (positions 1-3 have old values)
|
// pending_components: [C | C, D, D] (positions 1-3 have old values)
|
||||||
// pending_count: 1 ^--^
|
// pending_count: 1 ^--^
|
||||||
>>>>>>> upstream/dev
|
|
||||||
|
|
||||||
while (pending_count > 0 && (now - start_time) < timeout_ms) {
|
while (pending_count > 0 && (now - start_time) < timeout_ms) {
|
||||||
// Feed watchdog during teardown to prevent triggering
|
// Feed watchdog during teardown to prevent triggering
|
||||||
@@ -340,11 +317,7 @@ void Application::teardown_components(uint32_t timeout_ms) {
|
|||||||
size_t still_pending = 0;
|
size_t still_pending = 0;
|
||||||
for (size_t i = 0; i < pending_count; ++i) {
|
for (size_t i = 0; i < pending_count; ++i) {
|
||||||
if (!pending_components[i]->teardown()) {
|
if (!pending_components[i]->teardown()) {
|
||||||
<<<<<<< HEAD
|
|
||||||
// Component still needs time, keep it in the list
|
|
||||||
=======
|
|
||||||
// Component still needs time, copy it forward
|
// Component still needs time, copy it forward
|
||||||
>>>>>>> upstream/dev
|
|
||||||
if (still_pending != i) {
|
if (still_pending != i) {
|
||||||
pending_components[still_pending] = pending_components[i];
|
pending_components[still_pending] = pending_components[i];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user