Skip to content

Commit

Permalink
Replace use of removed Base.nothing_sentinel (#28)
Browse files Browse the repository at this point in the history
A better solution is to express Base's search functionality in terms of
searching over chunks of contiguous memory, as I have proposed elsewhere.
However, that will require a memory view API in Base.
  • Loading branch information
jakobnissen authored Oct 9, 2024
1 parent 292a9cc commit 6f9020c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/search.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# optimized string routines copied from julia/base/strings/search.jl

nothing_sentinel(x) = iszero(x) ? nothing : x

function Base.findnext(pred::Base.Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar},
s::StringViewAndSub, i::Integer)
if i < 1 || i > sizeof(s)
Expand All @@ -8,7 +10,7 @@ function Base.findnext(pred::Base.Fix2{<:Union{typeof(isequal),typeof(==)},<:Abs
end
@inbounds isvalid(s, i) || Base.string_index_err(s, i)
c = pred.x
c '\x7f' && return Base.nothing_sentinel(Base._search(s, c % UInt8, i))
c '\x7f' && return nothing_sentinel(Base._search(s, c % UInt8, i))
while true
i = Base._search(s, Base.first_utf8_byte(c), i)
i == 0 && return nothing
Expand Down Expand Up @@ -42,7 +44,7 @@ end
function Base.findprev(pred::Base.Fix2{<:Union{typeof(isequal),typeof(==)},<:AbstractChar},
s::StringViewAndSub, i::Integer)
c = pred.x
c '\x7f' && return Base.nothing_sentinel(Base._rsearch(s, c % UInt8, i))
c '\x7f' && return nothing_sentinel(Base._rsearch(s, c % UInt8, i))
b = Base.first_utf8_byte(c)
while true
i = Base._rsearch(s, b, i)
Expand Down

0 comments on commit 6f9020c

Please sign in to comment.