Skip to content

Commit 0da9eff

Browse files
kortschakrandall77
authored andcommitted
runtime: simplify syntax for pointer arithmetic in mapaccess functions
This harmonizes the syntax between mapaccess1 and mapaccess2, and simplifies the code. Change-Id: I6db25ffdc871018d399f9030259894b3994c5793 Reviewed-on: https://go-review.googlesource.com/c/go/+/308951 Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Keith Randall <[email protected]> Trust: Emmanuel Odeke <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 352d329 commit 0da9eff

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/runtime/map.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,13 +470,13 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool)
470470
}
471471
hash := t.hasher(key, uintptr(h.hash0))
472472
m := bucketMask(h.B)
473-
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize)))
473+
b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
474474
if c := h.oldbuckets; c != nil {
475475
if !h.sameSizeGrow() {
476476
// There used to be half as many buckets; mask down one more power of two.
477477
m >>= 1
478478
}
479-
oldb := (*bmap)(unsafe.Pointer(uintptr(c) + (hash&m)*uintptr(t.bucketsize)))
479+
oldb := (*bmap)(add(c, (hash&m)*uintptr(t.bucketsize)))
480480
if !evacuated(oldb) {
481481
b = oldb
482482
}
@@ -514,13 +514,13 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe
514514
}
515515
hash := t.hasher(key, uintptr(h.hash0))
516516
m := bucketMask(h.B)
517-
b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize)))
517+
b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize)))
518518
if c := h.oldbuckets; c != nil {
519519
if !h.sameSizeGrow() {
520520
// There used to be half as many buckets; mask down one more power of two.
521521
m >>= 1
522522
}
523-
oldb := (*bmap)(unsafe.Pointer(uintptr(c) + (hash&m)*uintptr(t.bucketsize)))
523+
oldb := (*bmap)(add(c, (hash&m)*uintptr(t.bucketsize)))
524524
if !evacuated(oldb) {
525525
b = oldb
526526
}

0 commit comments

Comments
 (0)