Skip to content

Commit

Permalink
speed up cmp(SubString,SubString)
Browse files Browse the repository at this point in the history
About 1.5x faster. Helps with JuliaLang#8826.
  • Loading branch information
nolta committed Nov 14, 2014
1 parent dff8e03 commit cf7f24f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ end

isascii(s::SubString{ASCIIString}) = true

function cmp{T<:ByteString,S<:ByteString}(a::SubString{T}, b::SubString{S})
na = sizeof(a)
nb = sizeof(b)
c = ccall(:memcmp, Int32, (Ptr{UInt8}, Ptr{UInt8}, UInt),
pointer(a), pointer(b), min(na,nb))
c < 0 ? -1 : c > 0 ? +1 : cmp(na,nb)
end

## hashing strings ##

const memhash = UInt === UInt64 ? :memhash_seed : :memhash32_seed
Expand Down

0 comments on commit cf7f24f

Please sign in to comment.