Skip to content

Commit

Permalink
Make findall slightly faster
Browse files Browse the repository at this point in the history
Take fast path not in every iteration, but just once, outside the loop.
  • Loading branch information
jakobnissen committed Sep 11, 2024
1 parent 7b15e9e commit ba4e410
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion base/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,14 @@ function findall(
pred::Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar},
s::Union{String, SubString{String}},
)
collect(FwCharPosIter(s, pred.x))
iter = FwCharPosIter(s, pred.x)
return if is_standalone_byte(iter.last_char_byte)
findall(==(iter.last_char_byte), codeunits(s))
else
# It is slightly wasteful that every iteration will check is_standalone_byte
# again, but this should only be minor overhead in the non-fast path.
collect(iter)
end
end

"""
Expand Down

0 comments on commit ba4e410

Please sign in to comment.