mirror of
https://github.com/golang/go
synced 2024-11-26 06:38:00 -07:00
hash/maphash: manually inline setSeed
Provides a minor performance win. name old time/op new time/op delta Hash8Bytes-8 16.5ns ± 2% 16.5ns ± 4% ~ (p=0.407 n=27+29) Hash320Bytes-8 58.5ns ± 2% 55.0ns ± 2% -6.01% (p=0.000 n=29+28) Hash1K-8 195ns ± 1% 190ns ± 2% -2.23% (p=0.000 n=30+30) Hash8K-8 1.59µs ± 2% 1.57µs ± 2% -0.88% (p=0.002 n=30+30) name old speed new speed delta Hash8Bytes-8 484MB/s ± 2% 485MB/s ± 4% ~ (p=0.417 n=27+29) Hash320Bytes-8 5.47GB/s ± 2% 5.82GB/s ± 2% +6.39% (p=0.000 n=29+28) Hash1K-8 5.26GB/s ± 1% 5.39GB/s ± 2% +2.29% (p=0.000 n=30+30) Hash8K-8 5.16GB/s ± 2% 5.21GB/s ± 2% +0.89% (p=0.002 n=30+30) Updates #42710 Change-Id: Ia0d7264b648f96099202de21c6b69a9c1776f6c8 Reviewed-on: https://go-review.googlesource.com/c/go/+/278759 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
86d6678429
commit
ae9cd1299c
@ -68,7 +68,9 @@ type Hash struct {
|
||||
// which does call h.initSeed.)
|
||||
func (h *Hash) initSeed() {
|
||||
if h.seed.s == 0 {
|
||||
h.setSeed(MakeSeed())
|
||||
seed := MakeSeed()
|
||||
h.seed = seed
|
||||
h.state = seed
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,17 +125,12 @@ func (h *Hash) Seed() Seed {
|
||||
// Two Hash objects with different seeds will very likely behave differently.
|
||||
// Any bytes added to h before this call will be discarded.
|
||||
func (h *Hash) SetSeed(seed Seed) {
|
||||
h.setSeed(seed)
|
||||
h.n = 0
|
||||
}
|
||||
|
||||
// setSeed sets seed without discarding accumulated data.
|
||||
func (h *Hash) setSeed(seed Seed) {
|
||||
if seed.s == 0 {
|
||||
panic("maphash: use of uninitialized Seed")
|
||||
}
|
||||
h.seed = seed
|
||||
h.state = seed
|
||||
h.n = 0
|
||||
}
|
||||
|
||||
// Reset discards all bytes added to h.
|
||||
|
Loading…
Reference in New Issue
Block a user