mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
Replace modulo with compare-and-reset for circular buffer indices
Modulo generates a full division on ESP8266 since API_MAX_SEND_QUEUE is not a power of 2. Use increment + compare instead.
This commit is contained in:
@@ -31,7 +31,8 @@ ssize_t APIOverflowBuffer::try_drain(socket::Socket *socket) {
|
||||
// Entry fully sent — free it and advance
|
||||
Entry::destroy(front);
|
||||
this->queue_[this->head_] = nullptr;
|
||||
this->head_ = (this->head_ + 1) % API_MAX_SEND_QUEUE;
|
||||
if (++this->head_ >= API_MAX_SEND_QUEUE)
|
||||
this->head_ = 0;
|
||||
this->count_--;
|
||||
}
|
||||
|
||||
@@ -62,7 +63,8 @@ bool APIOverflowBuffer::enqueue_iov(const struct iovec *iov, int iovcnt, uint16_
|
||||
}
|
||||
}
|
||||
|
||||
this->tail_ = (this->tail_ + 1) % API_MAX_SEND_QUEUE;
|
||||
if (++this->tail_ >= API_MAX_SEND_QUEUE)
|
||||
this->tail_ = 0;
|
||||
this->count_++;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user