diff options
| author | Keith Randall <khr@golang.org> | 2016-02-22 13:20:38 -0800 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2016-02-23 00:15:38 +0000 |
| commit | bd70bd9cb2f458b23222083a3a11190f080af7fd (patch) | |
| tree | 77c35258aea9e50c677841ef02af3b6a63871c10 /src/runtime/hashmap_fast.go | |
| parent | 1e00cc1647916b705682f8721b8a9e9e095bf4ee (diff) | |
| download | go-bd70bd9cb2f458b23222083a3a11190f080af7fd.tar.xz | |
runtime: unify memeq and memequal
They do the same thing, except memequal also has the short-circuit
check if the two pointers are equal.
A) We might as well always do the short-circuit check, it is only 2 instructions.
B) The extra function call (memequal->memeq) is expensive.
benchmark old ns/op new ns/op delta
BenchmarkArrayEqual-8 8.56 5.31 -37.97%
No noticeable affect on the former memeq user (maps).
Fixes #14302
Change-Id: I85d1ada59ed11e64dd6c54667f79d32cc5f81948
Reviewed-on: https://go-review.googlesource.com/19843
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/runtime/hashmap_fast.go')
| -rw-r--r-- | src/runtime/hashmap_fast.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/runtime/hashmap_fast.go b/src/runtime/hashmap_fast.go index 519dc77f71..f95ea3e1b7 100644 --- a/src/runtime/hashmap_fast.go +++ b/src/runtime/hashmap_fast.go @@ -216,7 +216,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer { if k.len != key.len { continue } - if k.str == key.str || memeq(k.str, key.str, uintptr(key.len)) { + if k.str == key.str || memequal(k.str, key.str, uintptr(key.len)) { return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*sys.PtrSize+i*uintptr(t.valuesize)) } } @@ -254,7 +254,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer { } if keymaybe != bucketCnt { k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+keymaybe*2*sys.PtrSize)) - if memeq(k.str, key.str, uintptr(key.len)) { + if memequal(k.str, key.str, uintptr(key.len)) { return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*sys.PtrSize+keymaybe*uintptr(t.valuesize)) } } @@ -284,7 +284,7 @@ dohash: if k.len != key.len { continue } - if k.str == key.str || memeq(k.str, key.str, uintptr(key.len)) { + if k.str == key.str || memequal(k.str, key.str, uintptr(key.len)) { return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*sys.PtrSize+i*uintptr(t.valuesize)) } } @@ -321,7 +321,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) { if k.len != key.len { continue } - if k.str == key.str || memeq(k.str, key.str, uintptr(key.len)) { + if k.str == key.str || memequal(k.str, key.str, uintptr(key.len)) { return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*sys.PtrSize+i*uintptr(t.valuesize)), true } } @@ -357,7 +357,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) { } if keymaybe != bucketCnt { k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+keymaybe*2*sys.PtrSize)) - if memeq(k.str, key.str, uintptr(key.len)) { + if memequal(k.str, key.str, uintptr(key.len)) { return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*sys.PtrSize+keymaybe*uintptr(t.valuesize)), true } } @@ -387,7 +387,7 @@ dohash: if k.len != key.len { continue } - if k.str == key.str || memeq(k.str, key.str, uintptr(key.len)) { + if k.str == key.str || memequal(k.str, key.str, uintptr(key.len)) { return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*sys.PtrSize+i*uintptr(t.valuesize)), true } } |
