mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: don't use statictmps for small object in slice literal
Fixes #21561 Change-Id: I89c59752060dd9570d17d73acbbaceaefce5d8ce Reviewed-on: https://go-review.googlesource.com/c/go/+/197560 Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
ecba83520d
commit
77f5adba55
3 changed files with 68 additions and 1 deletions
|
|
@ -582,6 +582,16 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
|
|||
}
|
||||
}
|
||||
|
||||
func isSmallSliceLit(n *Node) bool {
|
||||
if n.Op != OSLICELIT {
|
||||
return false
|
||||
}
|
||||
|
||||
r := n.Right
|
||||
|
||||
return smallintconst(r) && (n.Type.Elem().Width == 0 || r.Int64() <= smallArrayBytes/n.Type.Elem().Width)
|
||||
}
|
||||
|
||||
func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
|
||||
// make an array type corresponding the number of elements we have
|
||||
t := types.NewArray(n.Type.Elem(), n.Right.Int64())
|
||||
|
|
@ -639,7 +649,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
|
|||
var vstat *Node
|
||||
|
||||
mode := getdyn(n, true)
|
||||
if mode&initConst != 0 {
|
||||
if mode&initConst != 0 && !isSmallSliceLit(n) {
|
||||
vstat = staticname(t)
|
||||
if ctxt == inInitFunction {
|
||||
vstat.Name.SetReadonly(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue