mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
compile/internal/walk: add walkGrowslice
Move growslice generation to a separate func so that specialization logic can be shared. Updates #49480 Change-Id: I9ea5bb898753622d2d767546a46b4db6410dc725 Reviewed-on: https://go-review.googlesource.com/c/go/+/495877 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
parent
0e1a9e1867
commit
a2647f08f0
@ -513,11 +513,8 @@ func appendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
|
||||
slice.SetBounded(true)
|
||||
nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, s, slice)}
|
||||
|
||||
// func growslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, et *_type) []T
|
||||
fn := typecheck.LookupRuntime("growslice", elemtype, elemtype)
|
||||
|
||||
// else { s = growslice(oldPtr, newLen, oldCap, num, T) }
|
||||
call := mkcall1(fn, s.Type(), nif.PtrInit(), oldPtr, newLen, oldCap, num, reflectdata.TypePtrAt(base.Pos, elemtype))
|
||||
call := walkGrowslice(s, nif.PtrInit(), oldPtr, newLen, oldCap, num)
|
||||
nif.Else = []ir.Node{ir.NewAssignStmt(base.Pos, s, call)}
|
||||
|
||||
nodes.Append(nif)
|
||||
@ -691,17 +688,13 @@ func extendSlice(n *ir.CallExpr, init *ir.Nodes) ir.Node {
|
||||
nt.SetBounded(true)
|
||||
nif.Body = []ir.Node{ir.NewAssignStmt(base.Pos, s, nt)}
|
||||
|
||||
// instantiate growslice(oldPtr *any, newLen, oldCap, num int, typ *type) []any
|
||||
fn := typecheck.LookupRuntime("growslice", elemtype, elemtype)
|
||||
|
||||
// else { s = growslice(s.ptr, n, s.cap, l2, T) }
|
||||
nif.Else = []ir.Node{
|
||||
ir.NewAssignStmt(base.Pos, s, mkcall1(fn, s.Type(), nif.PtrInit(),
|
||||
ir.NewAssignStmt(base.Pos, s, walkGrowslice(s, nif.PtrInit(),
|
||||
ir.NewUnaryExpr(base.Pos, ir.OSPTR, s),
|
||||
nn,
|
||||
ir.NewUnaryExpr(base.Pos, ir.OCAP, s),
|
||||
l2,
|
||||
reflectdata.TypePtrAt(base.Pos, elemtype))),
|
||||
l2)),
|
||||
}
|
||||
|
||||
nodes = append(nodes, nif)
|
||||
|
@ -101,17 +101,13 @@ func walkAppend(n *ir.CallExpr, init *ir.Nodes, dst ir.Node) ir.Node {
|
||||
ir.NewAssignStmt(base.Pos, s, slice),
|
||||
}
|
||||
|
||||
// growslice(ptr *T, newLen, oldCap, num int, <type>) (ret []T)
|
||||
fn := typecheck.LookupRuntime("growslice", s.Type().Elem(), s.Type().Elem())
|
||||
|
||||
// else { s = growslice(s.ptr, n, s.cap, a, T) }
|
||||
nif.Else = []ir.Node{
|
||||
ir.NewAssignStmt(base.Pos, s, mkcall1(fn, s.Type(), nif.PtrInit(),
|
||||
ir.NewAssignStmt(base.Pos, s, walkGrowslice(s, nif.PtrInit(),
|
||||
ir.NewUnaryExpr(base.Pos, ir.OSPTR, s),
|
||||
newLen,
|
||||
ir.NewUnaryExpr(base.Pos, ir.OCAP, s),
|
||||
num,
|
||||
reflectdata.TypePtrAt(base.Pos, s.Type().Elem()))),
|
||||
num)),
|
||||
}
|
||||
|
||||
l = append(l, nif)
|
||||
@ -130,6 +126,14 @@ func walkAppend(n *ir.CallExpr, init *ir.Nodes, dst ir.Node) ir.Node {
|
||||
return s
|
||||
}
|
||||
|
||||
// growslice(ptr *T, newLen, oldCap, num int, <type>) (ret []T)
|
||||
func walkGrowslice(slice *ir.Name, init *ir.Nodes, oldPtr, newLen, oldCap, num ir.Node) *ir.CallExpr {
|
||||
elemtype := slice.Type().Elem()
|
||||
fn := typecheck.LookupRuntime("growslice", elemtype, elemtype)
|
||||
elemtypeptr := reflectdata.TypePtrAt(base.Pos, elemtype)
|
||||
return mkcall1(fn, slice.Type(), init, oldPtr, newLen, oldCap, num, elemtypeptr)
|
||||
}
|
||||
|
||||
// walkClear walks an OCLEAR node.
|
||||
func walkClear(n *ir.UnaryExpr) ir.Node {
|
||||
typ := n.X.Type()
|
||||
|
Loading…
Reference in New Issue
Block a user