From 1c63ecf06239d0ea60ebf18785505e013228e404 Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Fri, 25 Oct 2024 21:38:39 +0200 Subject: [PATCH] Use part when counting over chunk iterators (#326) This somewhat speeds up counting operations for sequence views, making them nearly as fast as non-view LongSequence. --- src/counting.jl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/counting.jl b/src/counting.jl index bafbf00d..753628b4 100644 --- a/src/counting.jl +++ b/src/counting.jl @@ -18,13 +18,15 @@ trunc_seq(x::LongSubSeq, len::Int) = typeof(x)(x.data, first(x.part):first(x.par y end -@inline function counter_1seq(tail::Function, body::Function, seq::SeqOrView) - (it, (chunk, rm)) = @inline iter_chunks(seq) - y = @inline tail(chunk, rm) - for i in it - y += @inline body(i) +@inline function counter_1seq(partial::Function, body::Function, seq::SeqOrView) + ((head, head_bits), (chunk_start, chunk_end), (tail, tail_bits)) = parts(seq) + y = @inline partial(head, head_bits) + @inline partial(tail, tail_bits) + data = seq.data + @inbounds for i in chunk_start:chunk_end + y += @inline body(data[i]) end y + y end """