From b864a15d4d2eac5a42d852c4b770cc9684ef473e Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 11 Oct 2018 22:14:23 -0400 Subject: [PATCH] improve performance for ascii --- base/strings/util.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/base/strings/util.jl b/base/strings/util.jl index fc473568646ec..d733662f4e3ce 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -597,14 +597,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)