Skip to content

Commit

Permalink
runtime: rtypeList cache for NewNamed
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Sep 22, 2024
1 parent 7955830 commit 3aefb3b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
9 changes: 0 additions & 9 deletions internal/runtime/types/types.go

This file was deleted.

16 changes: 12 additions & 4 deletions internal/runtime/z_face.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/goplus/llgo/c"
"github.com/goplus/llgo/internal/abi"
"github.com/goplus/llgo/internal/runtime/types"
)

type eface struct {
Expand Down Expand Up @@ -107,14 +106,23 @@ func hdrSizeOf(kind abi.Kind) uintptr {
}
}

type rtype struct {
*abi.Type
named string
}

var rtypeList []*rtype

// NewNamed returns an uninitialized named type.
func NewNamed(name string, kind abi.Kind, size uintptr, methods, ptrMethods int) *Type {
if t, ok := types.Map[name]; ok {
return (*Type)(t)
for _, typ := range rtypeList {
if typ.named == name {
return typ.Type
}
}
ret := newUninitedNamed(kind, size, methods)
ret.PtrToThis_ = newUninitedNamed(abi.Pointer, pointerSize, ptrMethods)
types.Map[name] = unsafe.Pointer(ret)
rtypeList = append(rtypeList, &rtype{Type: ret, named: name})
return ret
}

Expand Down
3 changes: 2 additions & 1 deletion ssa/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,9 @@ func (p Program) NewPackage(name, pkgPath string) Package {
// p.needPyInit = false
ret := &aPackage{
mod: mod, vars: gbls, fns: fns, stubs: stubs,
pyobjs: pyobjs, pymods: pymods, strs: strs, Prog: p,
di: nil, cu: nil, glbDbgVars: glbDbgVars,
pyobjs: pyobjs, pymods: pymods, strs: strs, Prog: p}
}
ret.abi.Init(pkgPath)
return ret
}
Expand Down

0 comments on commit 3aefb3b

Please sign in to comment.