Skip to content

Commit

Permalink
Use part when counting over chunk iterators (#326)
Browse files Browse the repository at this point in the history
This somewhat speeds up counting operations for sequence views, making them
nearly as fast as non-view LongSequence.
  • Loading branch information
jakobnissen authored Oct 25, 2024
1 parent 1473594 commit 1c63ecf
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/counting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down

0 comments on commit 1c63ecf

Please sign in to comment.