Skip to content

Commit d56f4b6

Browse files
authored
use Base.hash_bytes on latest julia (#30)
* use Base.hash_bytes on latest julia * whoops
1 parent 82d6786 commit d56f4b6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/StringViews.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,12 @@ Base.@propagate_inbounds Base.nextind(s::StringViewAndSub, i::Int) = Base._nexti
114114
Base.isvalid(s::StringViewAndSub, i::Int) = checkbounds(Bool, s, i) && thisind(s, i) == i
115115

116116
function Base.hash(s::DenseStringViewAndSub, h::UInt)
117-
h += Base.memhash_seed
118-
ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), s, ncodeunits(s), h % UInt32) + h
117+
@static if isdefined(Base, :hash_bytes)
118+
GC.@preserve s Base.hash_bytes(pointer(s), sizeof(s), UInt64(h), Base.HASH_SECRET) % UInt
119+
else
120+
h += Base.memhash_seed
121+
ccall(Base.memhash, UInt, (Ptr{UInt8}, Csize_t, UInt32), s, ncodeunits(s), h % UInt32) + h
122+
end
119123
end
120124

121125
# each string type must implement its own reverse because it is generally

0 commit comments

Comments
 (0)