Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In string search, replace unsafe_wrap with codeunits #48275

Merged
merged 1 commit into from
Jan 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions base/strings/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function _search(a::ByteArray, b::AbstractChar, i::Integer = 1)
if isascii(b)
_search(a,UInt8(b),i)
else
_search(a,unsafe_wrap(Vector{UInt8},string(b)),i).start
_search(a,codeunits(string(b)),i).start
end
end

Expand Down Expand Up @@ -98,7 +98,7 @@ function _rsearch(a::ByteArray, b::AbstractChar, i::Integer = length(a))
if isascii(b)
_rsearch(a,UInt8(b),i)
else
_rsearch(a,unsafe_wrap(Vector{UInt8},string(b)),i).start
_rsearch(a,codeunits(string(b)),i).start
end
end

Expand Down Expand Up @@ -207,7 +207,7 @@ _nthbyte(t::AbstractVector, index) = t[index + (firstindex(t)-1)]
function _searchindex(s::String, t::String, i::Integer)
# Check for fast case of a single byte
lastindex(t) == 1 && return something(findnext(isequal(t[1]), s, i), 0)
_searchindex(unsafe_wrap(Vector{UInt8},s), unsafe_wrap(Vector{UInt8},t), i)
_searchindex(codeunits(s), codeunits(t), i)
end

function _searchindex(s::AbstractVector{<:Union{Int8,UInt8}},
Expand Down Expand Up @@ -521,7 +521,7 @@ function _rsearchindex(s::String, t::String, i::Integer)
return something(findprev(isequal(t[1]), s, i), 0)
elseif lastindex(t) != 0
j = i ≤ ncodeunits(s) ? nextind(s, i)-1 : i
return _rsearchindex(unsafe_wrap(Vector{UInt8}, s), unsafe_wrap(Vector{UInt8}, t), j)
return _rsearchindex(codeunits(s), codeunits(t), j)
elseif i > sizeof(s)
return 0
elseif i == 0
Expand Down