@@ -613,6 +613,38 @@ isascii(c::Char) = bswap(reinterpret(UInt32, c)) < 0x80
613613isascii (s:: AbstractString ) = all (isascii, s)
614614isascii (c:: AbstractChar ) = UInt32 (c) < 0x80
615615
616+ @inline function _isascii (code_units:: AbstractVector{CU} , first, last) where {CU}
617+ r = zero (CU)
618+ for n = first: last
619+ @inbounds r |= code_units[n]
620+ end
621+ return 0 ≤ r < 0x80
622+ end
623+
624+ # The chunking algorithm makes the last two chunks overlap inorder to keep the size fixed
625+ @inline function _isascii_chunks (chunk_size,cu:: AbstractVector{CU} , first,last) where {CU}
626+ n= first
627+ while n <= last - chunk_size
628+ _isascii (cu,n,n+ chunk_size- 1 ) || return false
629+ n += chunk_size
630+ end
631+ return _isascii (cu,last- chunk_size+ 1 ,last)
632+ end
633+ """
634+ isascii(cu::AbstractVector{CU}) where {CU <: Integer} -> Bool
635+
636+ Test whether all values in the vector belong to the ASCII character set (0x00 to 0x7f).
637+ This function is intended to be used by other string implementations that need a fast ASCII check.
638+ """
639+ function isascii (cu:: AbstractVector{CU} ) where {CU <: Integer }
640+ chunk_size = 1024
641+ chunk_threshold = chunk_size + (chunk_size ÷ 2 )
642+ first = firstindex (cu); last = lastindex (cu)
643+ l = last - first + 1
644+ l < chunk_threshold && return _isascii (cu,first,last)
645+ return _isascii_chunks (chunk_size,cu,first,last)
646+ end
647+
616648# # string map, filter ##
617649
618650function map (f, s:: AbstractString )
0 commit comments