From bdeea2983681907f83de070b0078fe41aae1bb81 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 12:04:32 -1000 Subject: [PATCH] Revert "Replace modulo with compare-and-reset for circular buffer indices" This reverts commit c03dd86796b8fa91ba58bf24d157373175ced17e. --- esphome/components/api/api_overflow_buffer.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_overflow_buffer.cpp b/esphome/components/api/api_overflow_buffer.cpp index 76b70c624e..af3b670e0e 100644 --- a/esphome/components/api/api_overflow_buffer.cpp +++ b/esphome/components/api/api_overflow_buffer.cpp @@ -31,8 +31,7 @@ ssize_t APIOverflowBuffer::try_drain(socket::Socket *socket) { // Entry fully sent — free it and advance Entry::destroy(front); this->queue_[this->head_] = nullptr; - if (++this->head_ >= API_MAX_SEND_QUEUE) - this->head_ = 0; + this->head_ = (this->head_ + 1) % API_MAX_SEND_QUEUE; this->count_--; } @@ -63,8 +62,7 @@ bool APIOverflowBuffer::enqueue_iov(const struct iovec *iov, int iovcnt, uint16_ } } - if (++this->tail_ >= API_MAX_SEND_QUEUE) - this->tail_ = 0; + this->tail_ = (this->tail_ + 1) % API_MAX_SEND_QUEUE; this->count_++; return true; }