]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile,runtime: pass elem type to {make,grow}slice
authorKeith Randall <khr@golang.org>
Tue, 19 Apr 2016 22:38:59 +0000 (15:38 -0700)
committerKeith Randall <khr@golang.org>
Wed, 20 Apr 2016 00:31:16 +0000 (00:31 +0000)
No point in passing the slice type to these functions.
All they need is the element type.  One less indirection,
maybe a few less []T type descriptors in the binary.

Change-Id: Ib0b83b5f14ca21d995ecc199ce8ac00c4eb375e6
Reviewed-on: https://go-review.googlesource.com/22275
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/cgen.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/walk.go
src/runtime/slice.go

index 658cc8a50ef532895003abc93f55590059a3624f..5c5bedaa314d8e64ac5f6ba9e9b24ba898f62908 100644 (file)
@@ -2876,7 +2876,7 @@ func cgen_append(n, res *Node) {
        arg.Addable = true
        arg.Xoffset = Ctxt.FixedFrameSize()
        arg.Type = Ptrto(Types[TUINT8])
-       Cgen(typename(res.Type), &arg)
+       Cgen(typename(res.Type.Elem()), &arg)
        arg.Xoffset += int64(Widthptr)
 
        arg.Type = Types[Tptr]
index c4008c9ce1c348b27fc81f1581d2c94cd25f9a27..11e362c1161d5800075de6632ee784de24715eb8 100644 (file)
@@ -2185,7 +2185,7 @@ func (s *state) append(n *Node, inplace bool) *ssa.Value {
 
        // Call growslice
        s.startBlock(grow)
-       taddr := s.newValue1A(ssa.OpAddr, Types[TUINTPTR], &ssa.ExternSymbol{Types[TUINTPTR], typenamesym(n.Type)}, s.sb)
+       taddr := s.newValue1A(ssa.OpAddr, Types[TUINTPTR], &ssa.ExternSymbol{Types[TUINTPTR], typenamesym(n.Type.Elem())}, s.sb)
 
        r := s.rtcall(growslice, true, []*Type{pt, Types[TINT], Types[TINT]}, taddr, p, l, c, nl)
 
index e4d93339a923bcd10c3605763755098c5b14009a..82ac74ae336fe6e176b813cd53a26bcdf96b9d74 100644 (file)
@@ -1420,11 +1420,11 @@ opswitch:
                        r = walkexpr(r, init)
                        n = r
                } else {
-                       // makeslice(t *Type, nel int64, max int64) (ary []any)
+                       // makeslice(et *Type, nel int64, max int64) (ary []any)
                        fn := syslook("makeslice")
 
                        fn = substArgTypes(fn, t.Elem()) // any-1
-                       n = mkcall1(fn, n.Type, init, typename(n.Type), conv(l, Types[TINT64]), conv(r, Types[TINT64]))
+                       n = mkcall1(fn, n.Type, init, typename(t.Elem()), conv(l, Types[TINT64]), conv(r, Types[TINT64]))
                }
 
        case ORUNESTR:
@@ -2799,7 +2799,7 @@ func appendslice(n *Node, init *Nodes) *Node {
        fn = substArgTypes(fn, s.Type.Elem(), s.Type.Elem())
 
        // s = growslice(T, s, n)
-       nif.Nbody.Set1(Nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type), s, nn)))
+       nif.Nbody.Set1(Nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type.Elem()), s, nn)))
        l = append(l, nif)
 
        // s = s[:n]
@@ -2929,7 +2929,7 @@ func walkappend(n *Node, init *Nodes, dst *Node) *Node {
        fn = substArgTypes(fn, ns.Type.Elem(), ns.Type.Elem())
 
        nx.Nbody.Set1(Nod(OAS, ns,
-               mkcall1(fn, ns.Type, &nx.Ninit, typename(ns.Type), ns,
+               mkcall1(fn, ns.Type, &nx.Ninit, typename(ns.Type.Elem()), ns,
                        Nod(OADD, Nod(OLEN, ns, nil), na))))
 
        l = append(l, nx)
index 873e97ebff3821d84083a3ee42d230b12b10bfc4..e86c1ce2c85aa2b760e737b6e0e0db2d66ffa43c 100644 (file)
@@ -37,14 +37,14 @@ func maxSliceCap(elemsize uintptr) uintptr {
 }
 
 // TODO: take uintptrs instead of int64s?
-func makeslice(t *slicetype, len64, cap64 int64) slice {
+func makeslice(et *_type, len64, cap64 int64) slice {
        // NOTE: The len > maxElements check here is not strictly necessary,
        // but it produces a 'len out of range' error instead of a 'cap out of range' error
        // when someone does make([]T, bignumber). 'cap out of range' is true too,
        // but since the cap is only being supplied implicitly, saying len is clearer.
        // See issue 4085.
 
-       maxElements := maxSliceCap(t.elem.size)
+       maxElements := maxSliceCap(et.size)
        len := int(len64)
        if len64 < 0 || int64(len) != len64 || uintptr(len) > maxElements {
                panic(errorString("makeslice: len out of range"))
@@ -55,7 +55,6 @@ func makeslice(t *slicetype, len64, cap64 int64) slice {
                panic(errorString("makeslice: cap out of range"))
        }
 
-       et := t.elem
        var flags uint32
        if et.kind&kindNoPointers != 0 {
                flags = flagNoScan
@@ -65,7 +64,7 @@ func makeslice(t *slicetype, len64, cap64 int64) slice {
 }
 
 // growslice handles slice growth during append.
-// It is passed the slice type, the old slice, and the desired new minimum capacity,
+// It is passed the slice element type, the old slice, and the desired new minimum capacity,
 // and it returns a new slice with at least that capacity, with the old data
 // copied into it.
 // The new slice's length is set to the old slice's length,
@@ -74,16 +73,15 @@ func makeslice(t *slicetype, len64, cap64 int64) slice {
 // to calculate where to write new values during an append.
 // TODO: When the old backend is gone, reconsider this decision.
 // The SSA backend might prefer the new length or to return only ptr/cap and save stack space.
-func growslice(t *slicetype, old slice, cap int) slice {
+func growslice(et *_type, old slice, cap int) slice {
        if raceenabled {
-               callerpc := getcallerpc(unsafe.Pointer(&t))
-               racereadrangepc(old.array, uintptr(old.len*int(t.elem.size)), callerpc, funcPC(growslice))
+               callerpc := getcallerpc(unsafe.Pointer(&et))
+               racereadrangepc(old.array, uintptr(old.len*int(et.size)), callerpc, funcPC(growslice))
        }
        if msanenabled {
-               msanread(old.array, uintptr(old.len*int(t.elem.size)))
+               msanread(old.array, uintptr(old.len*int(et.size)))
        }
 
-       et := t.elem
        if et.size == 0 {
                if cap < old.cap {
                        panic(errorString("growslice: cap out of range"))