diff --git a/go.mod b/go.mod index f4e3d4e3..7dc89400 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.starlark.net -go 1.18 +go 1.19 require ( github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e diff --git a/starlark/hashtable.go b/starlark/hashtable.go index 40f72bb6..7a427618 100644 --- a/starlark/hashtable.go +++ b/starlark/hashtable.go @@ -6,8 +6,8 @@ package starlark import ( "fmt" + "hash/maphash" "math/big" - _ "unsafe" // for go:linkname hack ) // hashtable is used to represent Starlark dict and set values. @@ -416,21 +416,19 @@ func (it *keyIterator) Done() { } } -// TODO(adonovan): use go1.19's maphash.String. +var seed = maphash.MakeSeed() // hashString computes the hash of s. func hashString(s string) uint32 { if len(s) >= 12 { // Call the Go runtime's optimized hash implementation, - // which uses the AESENC instruction on amd64 machines. - return uint32(goStringHash(s, 0)) + // which uses the AES instructions on amd64 and arm64 machines. + h := maphash.String(seed, s) + return uint32(h>>32) | uint32(h) } return softHashString(s) } -//go:linkname goStringHash runtime.stringHash -func goStringHash(s string, seed uintptr) uintptr - // softHashString computes the 32-bit FNV-1a hash of s in software. func softHashString(s string) uint32 { var h uint32 = 2166136261