Skip to content

Commit ad1a8f9

Browse files
authored
Improve performance
1 parent 415bdab commit ad1a8f9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/CircularArrayBuffers.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,21 @@ Base.isempty(cb::CircularArrayBuffer) = cb.nframes == 0
4141

4242
@inline function _buffer_index(cb::CircularArrayBuffer, i::Int)
4343
ind = (cb.first - 1) * cb.step_size + i
44-
mod1(ind, length(cb.buffer))
44+
if ind > length(cb.buffer)
45+
ind - length(cb.buffer)
46+
else
47+
ind
48+
end
4549
end
4650

4751
@inline function _buffer_frame(cb::CircularArrayBuffer, i::Int)
4852
n = capacity(cb)
4953
idx = cb.first + i - 1
50-
mod1(idx, n)
54+
if idx > n
55+
idx - n
56+
else
57+
idx
58+
end
5159
end
5260

5361
_buffer_frame(cb::CircularArrayBuffer, I::Vector{Int}) = map(i -> _buffer_frame(cb, i), I)

0 commit comments

Comments
 (0)