From: Josh Bleecher Snyder Date: Fri, 11 Aug 2017 15:43:30 +0000 (-0700) Subject: runtime: calculate k only once in mapiternext X-Git-Tag: go1.10beta1~1585 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=589fc314af46e0d65a91fa1048ba319f1bf390a6;p=gostls13.git runtime: calculate k only once in mapiternext Make the calculation of k and v a bit lazier. None of the following code cares about indirect-vs-direct k, and it happens on all code paths, so check t.indirectkey earlier. Simplifies the code and reduces both machine code and stack size. Change-Id: I5ea4c0772848d7a4b15383baedb9a1f7feb47201 Reviewed-on: https://go-review.googlesource.com/55092 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 64ec84474e..f384964522 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -820,11 +820,14 @@ next: } for ; i < bucketCnt; i++ { offi := (i + it.offset) & (bucketCnt - 1) - k := add(unsafe.Pointer(b), dataOffset+uintptr(offi)*uintptr(t.keysize)) - v := add(unsafe.Pointer(b), dataOffset+bucketCnt*uintptr(t.keysize)+uintptr(offi)*uintptr(t.valuesize)) if b.tophash[offi] == empty || b.tophash[offi] == evacuatedEmpty { continue } + k := add(unsafe.Pointer(b), dataOffset+uintptr(offi)*uintptr(t.keysize)) + if t.indirectkey { + k = *((*unsafe.Pointer)(k)) + } + v := add(unsafe.Pointer(b), dataOffset+bucketCnt*uintptr(t.keysize)+uintptr(offi)*uintptr(t.valuesize)) if checkBucket != noCheck && !h.sameSizeGrow() { // Special case: iterator was started during a grow to a larger size // and the grow is not done yet. We're working on a bucket whose @@ -833,14 +836,10 @@ next: // through the oldbucket, skipping any keys that will go // to the other new bucket (each oldbucket expands to two // buckets during a grow). - k2 := k - if t.indirectkey { - k2 = *((*unsafe.Pointer)(k2)) - } - if t.reflexivekey || alg.equal(k2, k2) { + if t.reflexivekey || alg.equal(k, k) { // If the item in the oldbucket is not destined for // the current new bucket in the iteration, skip it. - hash := alg.hash(k2, uintptr(h.hash0)) + hash := alg.hash(k, uintptr(h.hash0)) if hash&(uintptr(1)<