]> Cypherpunks.ru repositories - gostls13.git/commitdiff
hash/maphash: manually inline setSeed
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 17 Dec 2020 04:22:58 +0000 (20:22 -0800)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 11 Mar 2021 18:50:12 +0000 (18:50 +0000)
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>
src/hash/maphash/maphash.go

index f7ef1b41e89653e02f74f5d70863aa9221b2edf8..c45964f89e4eb1db4bb4a3cff4ca045eca5ef74c 100644 (file)
@@ -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.