]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: mask a bounded slice access in hashmap evacuate
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 11 Aug 2017 15:21:31 +0000 (08:21 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 15 Aug 2017 00:19:22 +0000 (00:19 +0000)
Shaves a few instructions off.

Change-Id: I39f1b01ae7e770d632d5e77a6aa4b5a1f123b41a
Reviewed-on: https://go-review.googlesource.com/55090
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/hashmap.go

index 1f16fe4e56231b8585d7f88f41f7a1402f6032a4..22470a08e93ec5cdde5bc8f1f2e80783aec080d8 100644 (file)
@@ -1129,7 +1129,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
                                        dst.k = add(unsafe.Pointer(dst.b), dataOffset)
                                        dst.v = add(dst.k, bucketCnt*uintptr(t.keysize))
                                }
-                               dst.b.tophash[dst.i] = top
+                               dst.b.tophash[dst.i&(bucketCnt-1)] = top // mask dst.i as an optimization, to avoid a bounds check
                                if t.indirectkey {
                                        *(*unsafe.Pointer)(dst.k) = k2 // copy pointer
                                } else {