Skip to content

Commit

Permalink
starlark: update go.mod to drop go1.18 support (#529)
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 f864706 commit 981680b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x]
go-version: [1.19.x, 1.20.x, 1.21.x, 1.22.x]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
Expand Down
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 981680b

Please sign in to comment.