mirror of
https://github.com/esphome/esphome.git
synced 2025-10-24 04:33:49 +01:00
perf
This commit is contained in:
@@ -53,11 +53,13 @@ optional<float> SlidingWindowFilter::new_value(float value) {
|
|||||||
// Buffer not yet full - just append
|
// Buffer not yet full - just append
|
||||||
this->window_.push_back(value);
|
this->window_.push_back(value);
|
||||||
this->window_count_++;
|
this->window_count_++;
|
||||||
this->window_head_ = this->window_count_ % this->window_size_;
|
|
||||||
} else {
|
} else {
|
||||||
// Buffer full - overwrite oldest value (ring buffer)
|
// Buffer full - overwrite oldest value (ring buffer)
|
||||||
this->window_[this->window_head_] = value;
|
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
|
// Check if we should send a result
|
||||||
|
|||||||
Reference in New Issue
Block a user