Skip to content

Commit

Permalink
Use part when counting over chunk iterators
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 committed Oct 25, 2024
1 parent 1473594 commit 93e0dd0
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

Check warning on line 29 in src/counting.jl

View check run for this annotation

Codecov / codecov/patch

src/counting.jl#L29

Added line #L29 was not covered by tests
end

"""
Expand Down

0 comments on commit 93e0dd0

Please sign in to comment.