mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 13:03:39 +00:00
reflect: use SliceHeader and StringHeader variant for internal use
These variants uses an unsafe.Pointer instead of uintptr so that the pointer/non-pointer fields match those of real slices and strings. This may be necessary in the future once we switch to a precise garbage collector.
This commit is contained in:
committed by
Ron Evans
parent
711889bc3f
commit
c8742e2b96
@@ -24,15 +24,15 @@ func Swapper(slice interface{}) func(i, j int) {
|
||||
typ := v.typecode.Elem()
|
||||
size := typ.Size()
|
||||
|
||||
header := (*SliceHeader)(v.value)
|
||||
header := (*sliceHeader)(v.value)
|
||||
tmp := unsafe.Pointer(&make([]byte, size)[0])
|
||||
|
||||
return func(i, j int) {
|
||||
if uint(i) >= uint(header.Len) || uint(j) >= uint(header.Len) {
|
||||
if uint(i) >= uint(header.len) || uint(j) >= uint(header.len) {
|
||||
panic("reflect: slice index out of range")
|
||||
}
|
||||
val1 := unsafe.Pointer(header.Data + uintptr(i)*size)
|
||||
val2 := unsafe.Pointer(header.Data + uintptr(j)*size)
|
||||
val1 := unsafe.Pointer(uintptr(header.data) + uintptr(i)*size)
|
||||
val2 := unsafe.Pointer(uintptr(header.data) + uintptr(j)*size)
|
||||
memcpy(tmp, val1, size)
|
||||
memcpy(val1, val2, size)
|
||||
memcpy(val2, tmp, size)
|
||||
|
||||
Reference in New Issue
Block a user