aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/reflect/swapper.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-05-22 18:20:26 +0200
committerRon Evans <[email protected]>2021-05-22 21:41:06 +0200
commitc8742e2b9655ef0cc18ab7c5daa9cd370e3ea80b (patch)
treea560103ad9fcaf8c3a3e7af548cd76ca624839a6 /src/reflect/swapper.go
parent711889bc3fc8237dfb56c79befa11f984fb3e605 (diff)
downloadtinygo-c8742e2b9655ef0cc18ab7c5daa9cd370e3ea80b.tar.gz
tinygo-c8742e2b9655ef0cc18ab7c5daa9cd370e3ea80b.zip
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.
Diffstat (limited to 'src/reflect/swapper.go')
-rw-r--r--src/reflect/swapper.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/reflect/swapper.go b/src/reflect/swapper.go
index f3baaede5..82842de96 100644
--- a/src/reflect/swapper.go
+++ b/src/reflect/swapper.go
@@ -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)