mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: replace aindex with typArray
aindex is overkill when it's only ever used with known integer constants, so just use typArray directly instead. Change-Id: I43fc14e604172df859b3ad9d848d219bbe48e434 Reviewed-on: https://go-review.googlesource.com/30979 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
1af769da82
commit
032e2bd1eb
2 changed files with 7 additions and 31 deletions
|
|
@ -475,30 +475,6 @@ func nodbool(b bool) *Node {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func aindex(b *Node, t *Type) *Type {
|
|
||||||
hasbound := false
|
|
||||||
var bound int64
|
|
||||||
b = typecheck(b, Erv)
|
|
||||||
if b != nil {
|
|
||||||
switch consttype(b) {
|
|
||||||
default:
|
|
||||||
yyerror("array bound must be an integer expression")
|
|
||||||
|
|
||||||
case CTINT, CTRUNE:
|
|
||||||
hasbound = true
|
|
||||||
bound = b.Int64()
|
|
||||||
if bound < 0 {
|
|
||||||
yyerror("array bound must be non negative")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasbound {
|
|
||||||
return typSlice(t)
|
|
||||||
}
|
|
||||||
return typArray(t, bound)
|
|
||||||
}
|
|
||||||
|
|
||||||
// treecopy recursively copies n, with the exception of
|
// treecopy recursively copies n, with the exception of
|
||||||
// ONAME, OLITERAL, OTYPE, and non-iota ONONAME leaves.
|
// ONAME, OLITERAL, OTYPE, and non-iota ONONAME leaves.
|
||||||
// Copies of iota ONONAME nodes are assigned the current
|
// Copies of iota ONONAME nodes are assigned the current
|
||||||
|
|
|
||||||
|
|
@ -1547,7 +1547,7 @@ opswitch:
|
||||||
}
|
}
|
||||||
// var arr [r]T
|
// var arr [r]T
|
||||||
// n = arr[:l]
|
// n = arr[:l]
|
||||||
t = aindex(r, t.Elem()) // [r]T
|
t = typArray(t.Elem(), nonnegintconst(r)) // [r]T
|
||||||
var_ := temp(t)
|
var_ := temp(t)
|
||||||
a := nod(OAS, var_, nil) // zero temp
|
a := nod(OAS, var_, nil) // zero temp
|
||||||
a = typecheck(a, Etop)
|
a = typecheck(a, Etop)
|
||||||
|
|
@ -1585,7 +1585,7 @@ opswitch:
|
||||||
case ORUNESTR:
|
case ORUNESTR:
|
||||||
a := nodnil()
|
a := nodnil()
|
||||||
if n.Esc == EscNone {
|
if n.Esc == EscNone {
|
||||||
t := aindex(nodintconst(4), Types[TUINT8])
|
t := typArray(Types[TUINT8], 4)
|
||||||
var_ := temp(t)
|
var_ := temp(t)
|
||||||
a = nod(OADDR, var_, nil)
|
a = nod(OADDR, var_, nil)
|
||||||
}
|
}
|
||||||
|
|
@ -1597,7 +1597,7 @@ opswitch:
|
||||||
a := nodnil()
|
a := nodnil()
|
||||||
if n.Esc == EscNone {
|
if n.Esc == EscNone {
|
||||||
// Create temporary buffer for string on stack.
|
// Create temporary buffer for string on stack.
|
||||||
t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
|
t := typArray(Types[TUINT8], tmpstringbufsize)
|
||||||
|
|
||||||
a = nod(OADDR, temp(t), nil)
|
a = nod(OADDR, temp(t), nil)
|
||||||
}
|
}
|
||||||
|
|
@ -1623,7 +1623,7 @@ opswitch:
|
||||||
|
|
||||||
if n.Esc == EscNone {
|
if n.Esc == EscNone {
|
||||||
// Create temporary buffer for string on stack.
|
// Create temporary buffer for string on stack.
|
||||||
t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
|
t := typArray(Types[TUINT8], tmpstringbufsize)
|
||||||
|
|
||||||
a = nod(OADDR, temp(t), nil)
|
a = nod(OADDR, temp(t), nil)
|
||||||
}
|
}
|
||||||
|
|
@ -1636,7 +1636,7 @@ opswitch:
|
||||||
|
|
||||||
if n.Esc == EscNone {
|
if n.Esc == EscNone {
|
||||||
// Create temporary buffer for slice on stack.
|
// Create temporary buffer for slice on stack.
|
||||||
t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
|
t := typArray(Types[TUINT8], tmpstringbufsize)
|
||||||
|
|
||||||
a = nod(OADDR, temp(t), nil)
|
a = nod(OADDR, temp(t), nil)
|
||||||
}
|
}
|
||||||
|
|
@ -1653,7 +1653,7 @@ opswitch:
|
||||||
|
|
||||||
if n.Esc == EscNone {
|
if n.Esc == EscNone {
|
||||||
// Create temporary buffer for slice on stack.
|
// Create temporary buffer for slice on stack.
|
||||||
t := aindex(nodintconst(tmpstringbufsize), Types[TINT32])
|
t := typArray(Types[TINT32], tmpstringbufsize)
|
||||||
|
|
||||||
a = nod(OADDR, temp(t), nil)
|
a = nod(OADDR, temp(t), nil)
|
||||||
}
|
}
|
||||||
|
|
@ -2840,7 +2840,7 @@ func addstr(n *Node, init *Nodes) *Node {
|
||||||
// Don't allocate the buffer if the result won't fit.
|
// Don't allocate the buffer if the result won't fit.
|
||||||
if sz < tmpstringbufsize {
|
if sz < tmpstringbufsize {
|
||||||
// Create temporary buffer for result string on stack.
|
// Create temporary buffer for result string on stack.
|
||||||
t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
|
t := typArray(Types[TUINT8], tmpstringbufsize)
|
||||||
|
|
||||||
buf = nod(OADDR, temp(t), nil)
|
buf = nod(OADDR, temp(t), nil)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue