Skip to content

Commit

Permalink
go/types/typeutil: make Hasher stateless
Browse files Browse the repository at this point in the history
This CL makes Hasher an empty struct: consequently,
Hashers are stateless and all are equivalent.

Whatever optimization benefit Hasher had when it
was introduced is no longer evident: the benchmark
added in this CL went from 5.2ms (using the old
hasher) to 3.3ms (without). It also simplifies the
API and relaxes the concurrency constraints.

Fixes golang/go#69407

Change-Id: Ic6fa54451bee20cba72cd7133cf9afd38e7c3ca8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/612496
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
adonovan committed Dec 27, 2024
1 parent 6d4eee4 commit 412b5e9
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 152 deletions.
5 changes: 1 addition & 4 deletions go/ssa/interp/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ var (
// hashType returns a hash for t such that
// types.Identical(x, y) => hashType(x) == hashType(y).
func hashType(t types.Type) int {
mu.Lock()
h := int(hasher.Hash(t))
mu.Unlock()
return h
return int(hasher.Hash(t))
}

// usesBuiltinMap returns true if the built-in hash function and
Expand Down
Loading

0 comments on commit 412b5e9

Please sign in to comment.