aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/hashmap_fast.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2017-06-05 07:18:09 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2017-08-08 19:51:48 +0000
commit64bd2c49b4afb80c6f062f52eb3c748970771acf (patch)
tree1bf846894af0f7a35661bcce58ecfd7b163b3d81 /src/runtime/hashmap_fast.go
parentdabc361847f1daa8dee430fc6cf29c52e6f644cc (diff)
downloadgo-64bd2c49b4afb80c6f062f52eb3c748970771acf.tar.xz
runtime: simplify b.tophash[i] calculation
The compiler is now smart enough not to insert a bounds check. Not only is this simpler, it eliminates a LEAQ from the generated code. Change-Id: Ie90cbd11584542edd99edd5456d9b02c406e8063 Reviewed-on: https://go-review.googlesource.com/53892 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/hashmap_fast.go')
-rw-r--r--src/runtime/hashmap_fast.go30
1 files changed, 10 insertions, 20 deletions
diff --git a/src/runtime/hashmap_fast.go b/src/runtime/hashmap_fast.go
index 6f21624d32..18ceee46d8 100644
--- a/src/runtime/hashmap_fast.go
+++ b/src/runtime/hashmap_fast.go
@@ -45,8 +45,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
if k != key {
continue
}
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize))
@@ -94,8 +93,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
if k != key {
continue
}
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize)), true
@@ -143,8 +141,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
if k != key {
continue
}
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize))
@@ -192,8 +189,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
if k != key {
continue
}
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize)), true
@@ -223,8 +219,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
if key.len < 32 {
// short key, doing lots of comparisons is ok
for i := uintptr(0); i < bucketCnt; i++ {
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -240,8 +235,7 @@ func mapaccess1_faststr(t *maptype, h *hmap, ky string) unsafe.Pointer {
// long key, try not to do more comparisons than necessary
keymaybe := uintptr(bucketCnt)
for i := uintptr(0); i < bucketCnt; i++ {
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -293,8 +287,7 @@ dohash:
}
for {
for i := uintptr(0); i < bucketCnt; i++ {
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x != top {
+ if b.tophash[i] != top {
continue
}
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -330,8 +323,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
if key.len < 32 {
// short key, doing lots of comparisons is ok
for i := uintptr(0); i < bucketCnt; i++ {
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -347,8 +339,7 @@ func mapaccess2_faststr(t *maptype, h *hmap, ky string) (unsafe.Pointer, bool) {
// long key, try not to do more comparisons than necessary
keymaybe := uintptr(bucketCnt)
for i := uintptr(0); i < bucketCnt; i++ {
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x == empty {
+ if b.tophash[i] == empty {
continue
}
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))
@@ -400,8 +391,7 @@ dohash:
}
for {
for i := uintptr(0); i < bucketCnt; i++ {
- x := *((*uint8)(add(unsafe.Pointer(b), i))) // b.tophash[i] without the bounds check
- if x != top {
+ if b.tophash[i] != top {
continue
}
k := (*stringStruct)(add(unsafe.Pointer(b), dataOffset+i*2*sys.PtrSize))