From a4b14902db2f0d7fdba63d866b456a77c68b8655 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 15 Oct 2025 18:44:37 -1000 Subject: [PATCH] perf --- esphome/components/sensor/filter.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esphome/components/sensor/filter.cpp b/esphome/components/sensor/filter.cpp index 0e52f9d94f..4863c00a29 100644 --- a/esphome/components/sensor/filter.cpp +++ b/esphome/components/sensor/filter.cpp @@ -53,11 +53,13 @@ optional SlidingWindowFilter::new_value(float value) { // Buffer not yet full - just append this->window_.push_back(value); this->window_count_++; - this->window_head_ = this->window_count_ % this->window_size_; } else { // Buffer full - overwrite oldest value (ring buffer) this->window_[this->window_head_] = value; - this->window_head_ = (this->window_head_ + 1) % this->window_size_; + this->window_head_++; + if (this->window_head_ >= this->window_size_) { + this->window_head_ = 0; + } } // Check if we should send a result