mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-14 07:53:40 +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
+3
-8
@@ -243,13 +243,8 @@ func (ch *channel) push(value unsafe.Pointer) bool {
|
||||
|
||||
// copy value to buffer
|
||||
memcpy(
|
||||
unsafe.Pointer( // pointer to the base of the buffer + offset = pointer to destination element
|
||||
uintptr(ch.buf)+
|
||||
uintptr( // element size * equivalent slice index = offset
|
||||
ch.elementSize* // element size (bytes)
|
||||
ch.bufHead, // index of first available buffer entry
|
||||
),
|
||||
),
|
||||
unsafe.Add(ch.buf, // pointer to the base of the buffer + offset = pointer to destination element
|
||||
ch.elementSize*ch.bufHead), // element size * equivalent slice index = offset
|
||||
value,
|
||||
ch.elementSize,
|
||||
)
|
||||
@@ -274,7 +269,7 @@ func (ch *channel) pop(value unsafe.Pointer) bool {
|
||||
}
|
||||
|
||||
// compute address of source
|
||||
addr := unsafe.Pointer(uintptr(ch.buf) + (ch.elementSize * ch.bufTail))
|
||||
addr := unsafe.Add(ch.buf, (ch.elementSize * ch.bufTail))
|
||||
|
||||
// copy value from buffer
|
||||
memcpy(
|
||||
|
||||
Reference in New Issue
Block a user