diff options
| author | Josh Bleecher Snyder <josharian@gmail.com> | 2017-08-10 08:11:46 -0700 |
|---|---|---|
| committer | Josh Bleecher Snyder <josharian@gmail.com> | 2017-08-14 00:51:48 +0000 |
| commit | f5804ce4f3b0f9fa8b9d149edc7fd43c6134768c (patch) | |
| tree | 0e3ca8286e0ae04b82073de509e42803148d8849 /src/runtime/hashmap.go | |
| parent | aca92f352d6a5bc0b17cd39d3b1bbe23ae0bb5ac (diff) | |
| download | go-f5804ce4f3b0f9fa8b9d149edc7fd43c6134768c.tar.xz | |
runtime: simplify hashmap tooManyOverflowBuckets
This generates better code.
Masking B in the return statement should be unnecessary,
but the compiler is understandably not yet clever enough to see that.
Someday, it'd also be nice for the compiler to generate
a CMOV for the saturation if statement.
Change-Id: Ie1c157b21f5212610da1f3c7823a93816b3b61b9
Reviewed-on: https://go-review.googlesource.com/54656
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Diffstat (limited to 'src/runtime/hashmap.go')
| -rw-r--r-- | src/runtime/hashmap.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index c36ff470d6..676f04efd5 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -995,10 +995,11 @@ func tooManyOverflowBuckets(noverflow uint16, B uint8) bool { // If the threshold is too high, maps that grow and shrink can hold on to lots of unused memory. // "too many" means (approximately) as many overflow buckets as regular buckets. // See incrnoverflow for more details. - if B < 16 { - return noverflow >= uint16(1)<<B + if B > 15 { + B = 15 } - return noverflow >= 1<<15 + // The compiler doesn't see here that B < 16; mask B to generate shorter shift code. + return noverflow >= uint16(1)<<(B&15) } // growing reports whether h is growing. The growth may be to the same size or bigger. |
