From 0da9eff5034521ccc51c32ebaad5fae20d8345fe Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Sun, 11 Apr 2021 14:18:24 +0930 Subject: [PATCH] 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 --- src/runtime/map.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/map.go b/src/runtime/map.go index 40e19c92949..111db56b01a 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 }