From df9c1d840da66dea9b5aaf0a0ff3a61e82d4980b Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Thu, 6 Jun 2024 13:51:04 +0200 Subject: [PATCH] Make findall slightly faster Take fast path not in every iteration, but just once, outside the loop. --- base/strings/search.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/base/strings/search.jl b/base/strings/search.jl index 2d697eb8c11585..94bb6ef8da797a 100644 --- a/base/strings/search.jl +++ b/base/strings/search.jl @@ -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 """