]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: replace aindex with typArray
authorMatthew Dempsky <mdempsky@google.com>
Thu, 13 Oct 2016 06:28:36 +0000 (23:28 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 13 Oct 2016 07:23:53 +0000 (07:23 +0000)
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>
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/walk.go

index 449a5a62cbb77ef78886942e3b88b629906dd8a1..8fb5be41f7bd3959adeb002daadbdb45446f78fd 100644 (file)
@@ -475,30 +475,6 @@ func nodbool(b bool) *Node {
        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
 // ONAME, OLITERAL, OTYPE, and non-iota ONONAME leaves.
 // Copies of iota ONONAME nodes are assigned the current
index dcb80f72c9a6dc6786e0e5d0f418c3f7af3c8e60..fe2f4c3dad173a278bb2d1ceac890de28fcf2ceb 100644 (file)
@@ -1547,7 +1547,7 @@ opswitch:
                        }
                        // var arr [r]T
                        // n = arr[:l]
-                       t = aindex(r, t.Elem()) // [r]T
+                       t = typArray(t.Elem(), nonnegintconst(r)) // [r]T
                        var_ := temp(t)
                        a := nod(OAS, var_, nil) // zero temp
                        a = typecheck(a, Etop)
@@ -1585,7 +1585,7 @@ opswitch:
        case ORUNESTR:
                a := nodnil()
                if n.Esc == EscNone {
-                       t := aindex(nodintconst(4), Types[TUINT8])
+                       t := typArray(Types[TUINT8], 4)
                        var_ := temp(t)
                        a = nod(OADDR, var_, nil)
                }
@@ -1597,7 +1597,7 @@ opswitch:
                a := nodnil()
                if n.Esc == EscNone {
                        // Create temporary buffer for string on stack.
-                       t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
+                       t := typArray(Types[TUINT8], tmpstringbufsize)
 
                        a = nod(OADDR, temp(t), nil)
                }
@@ -1623,7 +1623,7 @@ opswitch:
 
                if n.Esc == EscNone {
                        // Create temporary buffer for string on stack.
-                       t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
+                       t := typArray(Types[TUINT8], tmpstringbufsize)
 
                        a = nod(OADDR, temp(t), nil)
                }
@@ -1636,7 +1636,7 @@ opswitch:
 
                if n.Esc == EscNone {
                        // Create temporary buffer for slice on stack.
-                       t := aindex(nodintconst(tmpstringbufsize), Types[TUINT8])
+                       t := typArray(Types[TUINT8], tmpstringbufsize)
 
                        a = nod(OADDR, temp(t), nil)
                }
@@ -1653,7 +1653,7 @@ opswitch:
 
                if n.Esc == EscNone {
                        // Create temporary buffer for slice on stack.
-                       t := aindex(nodintconst(tmpstringbufsize), Types[TINT32])
+                       t := typArray(Types[TINT32], tmpstringbufsize)
 
                        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.
                if sz < tmpstringbufsize {
                        // 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)
                }