From d41571ea5a55dcef2134fafbc81eca4325d82818 Mon Sep 17 00:00:00 2001 From: pfeatherstone <45853521+pfeatherstone@users.noreply.github.com> Date: Sat, 22 Apr 2023 04:37:19 +0100 Subject: [PATCH] 10X speedup (#2779) Co-authored-by: pf --- dlib/sliding_buffer/circular_buffer.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dlib/sliding_buffer/circular_buffer.h b/dlib/sliding_buffer/circular_buffer.h index 4fcc922d6..2de8922ec 100644 --- a/dlib/sliding_buffer/circular_buffer.h +++ b/dlib/sliding_buffer/circular_buffer.h @@ -49,7 +49,10 @@ namespace dlib << "\n\t i: " << i << "\n\t size(): " << size() ); - return data[(i+offset)%data.size()]; + auto index = i + offset; + if (index >= data.size()) + index -= data.size(); + return data[index]; } const T& operator[] ( unsigned long i) const @@ -61,7 +64,10 @@ namespace dlib << "\n\t i: " << i << "\n\t size(): " << size() ); - return data[(i+offset)%data.size()]; + auto index = i + offset; + if (index >= data.size()) + index -= data.size(); + return data[index]; } void resize(unsigned long size)