]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: unify cases in mapiternext
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 11 Aug 2017 15:48:10 +0000 (08:48 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 15 Aug 2017 00:19:36 +0000 (00:19 +0000)
The preceding cleanup made it clear that two cases
(have golden data, unreachable key) are handled identically.
Simplify the control flow to reflect that.

Simplifies the code and generates shorter machine code.

Change-Id: Id612e0da6679813e855506f47222c58ea6497d70
Reviewed-on: https://go-review.googlesource.com/55093
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 22470a08e93ec5cdde5bc8f1f2e80783aec080d8..d45bfdfe343d8023c8905a76e2f4f388b5bd6e01 100644 (file)
@@ -860,8 +860,12 @@ next:
                                }
                        }
                }
-               if b.tophash[offi] != evacuatedX && b.tophash[offi] != evacuatedY {
-                       // this is the golden data, we can return it.
+               if (b.tophash[offi] != evacuatedX && b.tophash[offi] != evacuatedY) ||
+                       !(t.reflexivekey || alg.equal(k, k)) {
+                       // This is the golden data, we can return it.
+                       // OR
+                       // key!=key, so the entry can't be deleted or updated, so we can just return it.
+                       // That's lucky for us because when key!=key we can't look it up successfully.
                        it.key = k
                        if t.indirectvalue {
                                v = *((*unsafe.Pointer)(v))
@@ -870,29 +874,17 @@ next:
                } else {
                        // The hash table has grown since the iterator was started.
                        // The golden data for this key is now somewhere else.
-                       if t.reflexivekey || alg.equal(k, k) {
-                               // Check the current hash table for the data.
-                               // This code handles the case where the key
-                               // has been deleted, updated, or deleted and reinserted.
-                               // NOTE: we need to regrab the key as it has potentially been
-                               // updated to an equal() but not identical key (e.g. +0.0 vs -0.0).
-                               rk, rv := mapaccessK(t, h, k)
-                               if rk == nil {
-                                       continue // key has been deleted
-                               }
-                               it.key = rk
-                               it.value = rv
-                       } else {
-                               // if key!=key then the entry can't be deleted or
-                               // updated, so we can just return it. That's lucky for
-                               // us because when key!=key we can't look it up
-                               // successfully in the current table.
-                               it.key = k
-                               if t.indirectvalue {
-                                       v = *((*unsafe.Pointer)(v))
-                               }
-                               it.value = v
+                       // Check the current hash table for the data.
+                       // This code handles the case where the key
+                       // has been deleted, updated, or deleted and reinserted.
+                       // NOTE: we need to regrab the key as it has potentially been
+                       // updated to an equal() but not identical key (e.g. +0.0 vs -0.0).
+                       rk, rv := mapaccessK(t, h, k)
+                       if rk == nil {
+                               continue // key has been deleted
                        }
+                       it.key = rk
+                       it.value = rv
                }
                it.bucket = bucket
                if it.bptr != b { // avoid unnecessary write barrier; see issue 14921