]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: simplify syntax for pointer arithmetic in mapaccess functions
authorDan Kortschak <dan@kortschak.io>
Sun, 11 Apr 2021 04:48:24 +0000 (14:18 +0930)
committerKeith Randall <khr@golang.org>
Sun, 11 Apr 2021 20:41:32 +0000 (20:41 +0000)
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 <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/runtime/map.go

index 40e19c92949d84418d11b07abc9536dcd4c962f9..111db56b01a2fe874767a6375b6c80d6588b3d4b 100644 (file)
@@ -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
                }