From e14057677704843072ebba5857c42c7706b4b8ad Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 3 Oct 2025 18:48:05 +0000 Subject: [PATCH] Fix compatibility with Julia 1.13+ memhash removal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove hash method definition when Base.memhash is not available. On Julia 1.13+, these AbstractString types will use the default AbstractString hash implementation which is now efficient and zero-copy based on codeunit/iterate. For Julia <1.13, continue using the memhash-based implementation for compatibility. Related to JuliaLang/julia#59697 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/poslenstrings.jl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/poslenstrings.jl b/src/poslenstrings.jl index a8220c0..3913897 100644 --- a/src/poslenstrings.jl +++ b/src/poslenstrings.jl @@ -94,16 +94,18 @@ function Base.cmp(a::PosLenString, b::PosLenString) return cmp(codeunits(a), codeunits(b)) end -function Base.hash(s::PosLenString, h::UInt) - h += Base.memhash_seed - if !escaped(s) - ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), pointer(s), len(s), h % UInt32) + h - else - # TODO: this is expensive, even for rare escaped PosLenString - # this makes it about 4x slower than hash(::String) - # alternative is to maybe take what's needed from MurmurHash3.jl to operate by codeunit - x = copy(codeunits(s)) - ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), pointer(x), sizeof(x), h % UInt32) + h +if isdefined(Base, :memhash) + function Base.hash(s::PosLenString, h::UInt) + h += Base.memhash_seed + if !escaped(s) + ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), pointer(s), len(s), h % UInt32) + h + else + # TODO: this is expensive, even for rare escaped PosLenString + # this makes it about 4x slower than hash(::String) + # alternative is to maybe take what's needed from MurmurHash3.jl to operate by codeunit + x = copy(codeunits(s)) + ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), pointer(x), sizeof(x), h % UInt32) + h + end end end