mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 20:43:40 +00:00
runtime: add gc layout info for some basic types
This commit is contained in:
@@ -64,6 +64,7 @@
|
||||
package reflect
|
||||
|
||||
import (
|
||||
"internal/gclayout"
|
||||
"internal/itoa"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -961,6 +962,26 @@ func (t *rawType) Align() int {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rawType) gcLayout() unsafe.Pointer {
|
||||
kind := r.Kind()
|
||||
|
||||
if kind < String {
|
||||
return gclayout.NoPtrs
|
||||
}
|
||||
|
||||
switch kind {
|
||||
case Pointer, UnsafePointer, Chan, Map:
|
||||
return gclayout.Pointer
|
||||
case String:
|
||||
return gclayout.String
|
||||
case Slice:
|
||||
return gclayout.Slice
|
||||
}
|
||||
|
||||
// Unknown (for now); let the conservative pointer scanning handle it
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldAlign returns the alignment if this type is used in a struct field. It
|
||||
// is currently an alias for Align() but this might change in the future.
|
||||
func (t *rawType) FieldAlign() int {
|
||||
|
||||
@@ -1479,7 +1479,8 @@ func MakeSlice(typ Type, len, cap int) Value {
|
||||
ulen := uint(len)
|
||||
ucap := uint(cap)
|
||||
maxSize := (^uintptr(0)) / 2
|
||||
elementSize := rtype.elem().Size()
|
||||
elem := rtype.elem()
|
||||
elementSize := elem.Size()
|
||||
if elementSize > 1 {
|
||||
maxSize /= uintptr(elementSize)
|
||||
}
|
||||
@@ -1493,7 +1494,9 @@ func MakeSlice(typ Type, len, cap int) Value {
|
||||
var slice sliceHeader
|
||||
slice.cap = uintptr(ucap)
|
||||
slice.len = uintptr(ulen)
|
||||
slice.data = alloc(size, nil)
|
||||
layout := elem.gcLayout()
|
||||
|
||||
slice.data = alloc(size, layout)
|
||||
|
||||
return Value{
|
||||
typecode: rtype,
|
||||
|
||||
Reference in New Issue
Block a user