mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 13:33:39 +00:00
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:
committed by
Ron Evans
parent
d98c0afbab
commit
4ec1e58aa6
@@ -26,7 +26,7 @@ func preinit() {
|
||||
ptr := unsafe.Pointer(&_sbss)
|
||||
for ptr != unsafe.Pointer(&_ebss) {
|
||||
*(*uint32)(ptr) = 0
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 4)
|
||||
ptr = unsafe.Add(ptr, 4)
|
||||
}
|
||||
|
||||
// Initialize .data: global variables initialized from flash.
|
||||
@@ -34,8 +34,8 @@ func preinit() {
|
||||
dst := unsafe.Pointer(&_sdata)
|
||||
for dst != unsafe.Pointer(&_edata) {
|
||||
*(*uint32)(dst) = *(*uint32)(src)
|
||||
dst = unsafe.Pointer(uintptr(dst) + 4)
|
||||
src = unsafe.Pointer(uintptr(src) + 4)
|
||||
dst = unsafe.Add(dst, 4)
|
||||
src = unsafe.Add(src, 4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user