Skip to content

Commit

Permalink
starlark: update go.mod to drop go1.18 support
Browse files Browse the repository at this point in the history
Also, use go1.19's maphash.String.
The benchmark supports continuing to use FNV for short strings.
  • Loading branch information
adonovan committed Mar 7, 2024
1 parent 2232540 commit 6809de2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.starlark.net

go 1.18
go 1.19

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
Expand Down
12 changes: 5 additions & 7 deletions starlark/hashtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6809de2

Please sign in to comment.