From: Dan Kortschak Date: Sun, 11 Apr 2021 04:48:24 +0000 (+0930) Subject: runtime: simplify syntax for pointer arithmetic in mapaccess functions X-Git-Tag: go1.17beta1~728 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0da9eff503;p=gostls13.git 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 Run-TryBot: Keith Randall Trust: Emmanuel Odeke TryBot-Result: Go Bot --- diff --git a/src/runtime/map.go b/src/runtime/map.go index 40e19c9294..111db56b01 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -470,13 +470,13 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool) } hash := t.hasher(key, uintptr(h.hash0)) m := bucketMask(h.B) - b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize))) + b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) if c := h.oldbuckets; c != nil { if !h.sameSizeGrow() { // There used to be half as many buckets; mask down one more power of two. m >>= 1 } - oldb := (*bmap)(unsafe.Pointer(uintptr(c) + (hash&m)*uintptr(t.bucketsize))) + oldb := (*bmap)(add(c, (hash&m)*uintptr(t.bucketsize))) if !evacuated(oldb) { b = oldb } @@ -514,13 +514,13 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe } hash := t.hasher(key, uintptr(h.hash0)) m := bucketMask(h.B) - b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + (hash&m)*uintptr(t.bucketsize))) + b := (*bmap)(add(h.buckets, (hash&m)*uintptr(t.bucketsize))) if c := h.oldbuckets; c != nil { if !h.sameSizeGrow() { // There used to be half as many buckets; mask down one more power of two. m >>= 1 } - oldb := (*bmap)(unsafe.Pointer(uintptr(c) + (hash&m)*uintptr(t.bucketsize))) + oldb := (*bmap)(add(c, (hash&m)*uintptr(t.bucketsize))) if !evacuated(oldb) { b = oldb }