all: use unsafe.Add instead of unsafe.Pointer(uintptr(...) + ...)

We have an optimization for this specific pattern, but it's really just
a hack. With the addition of unsafe.Add in Go 1.17 we can directly
specify the intent instead and eventually remove this special case.

The code is also easier to read.
This commit is contained in:
Ayke van Laethem
2022-12-21 16:14:36 +01:00
committed by Ron Evans
parent d98c0afbab
commit 4ec1e58aa6
29 changed files with 84 additions and 95 deletions
+2 -2
View File
@@ -57,8 +57,8 @@ func malloc(size uintptr) unsafe.Pointer
// Compare two same-size buffers for equality.
func memequal(x, y unsafe.Pointer, n uintptr) bool {
for i := uintptr(0); i < n; i++ {
cx := *(*uint8)(unsafe.Pointer(uintptr(x) + i))
cy := *(*uint8)(unsafe.Pointer(uintptr(y) + i))
cx := *(*uint8)(unsafe.Add(x, i))
cy := *(*uint8)(unsafe.Add(y, i))
if cx != cy {
return false
}