Skip to content

Commit

Permalink
improve performance for ascii (#29609)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC authored Oct 16, 2018
1 parent 0902d58 commit b72fc4c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,13 @@ bytes2hex(io::IO, a::AbstractArray{UInt8}) =
end

# check for pure ASCII-ness

function ascii(s::String)
for i = 1:sizeof(s)
b = codeunit(s,i)
b < 0x80 || throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))
for i in 1:sizeof(s)
@inbounds codeunit(s, i) < 0x80 || __throw_invalid_ascii(s, i)
end
return s
end
@noinline __throw_invalid_ascii(s, i) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))

"""
ascii(s::AbstractString)
Expand Down

0 comments on commit b72fc4c

Please sign in to comment.