From df1739c77d4eb4f700722b4eb70b6036df96a9b9 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 12 Dec 2014 13:45:19 -0800 Subject: runtime: if key type is reflexive, don't call equal(k, k) Most types are reflexive (k == k for all k of type t), so don't bother calling equal(k, k) when the key type is reflexive. Change-Id: Ia716b4198b8b298687843b94b878dbc5e8fc2c65 Reviewed-on: https://go-review.googlesource.com/1480 Reviewed-by: Russ Cox --- src/runtime/hashmap.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/runtime/hashmap.go') diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index b4e624423f..0aa7c60af6 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -652,7 +652,7 @@ next: if t.indirectkey { k2 = *((*unsafe.Pointer)(k2)) } - if alg.equal(k2, k2, uintptr(t.key.size)) { + if t.reflexivekey || alg.equal(k2, k2, uintptr(t.key.size)) { // If the item in the oldbucket is not destined for // the current new bucket in the iteration, skip it. hash := alg.hash(k2, uintptr(t.key.size), uintptr(h.hash0)) @@ -689,7 +689,7 @@ next: if t.indirectkey { k2 = *((*unsafe.Pointer)(k2)) } - if alg.equal(k2, k2, uintptr(t.key.size)) { + if t.reflexivekey || alg.equal(k2, k2, uintptr(t.key.size)) { // Check the current hash table for the data. // This code handles the case where the key // has been deleted, updated, or deleted and reinserted. @@ -798,7 +798,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { // to send this key/value to bucket x or bucket y). hash := alg.hash(k2, uintptr(t.key.size), uintptr(h.hash0)) if h.flags&iterator != 0 { - if !alg.equal(k2, k2, uintptr(t.key.size)) { + if !t.reflexivekey && !alg.equal(k2, k2, uintptr(t.key.size)) { // If key != key (NaNs), then the hash could be (and probably // will be) entirely different from the old hash. Moreover, // it isn't reproducible. Reproducibility is required in the -- cgit v1.3-5-g9baa