]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: use escape analysis result for make([]T, constant
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 30 May 2013 06:32:00 +0000 (08:32 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Thu, 30 May 2013 06:32:00 +0000 (08:32 +0200)
Escape analysis already gives that the underlying array
does not escape but the result was ignored.

Fixes #5484.

R=golang-dev, dave, daniel.morsing
CC=golang-dev
https://golang.org/cl/9662046

src/cmd/gc/walk.c

index 3dd8930969f9be8876a13018d1a13628c58984f6..a4e20e046c857e1c281b42206b8e029b79d2b673 100644 (file)
@@ -1246,18 +1246,35 @@ walkexpr(Node **np, NodeList **init)
                goto ret;
 
        case OMAKESLICE:
-               // makeslice(t *Type, nel int64, max int64) (ary []any)
                l = n->left;
                r = n->right;
                if(r == nil)
                        l = r = safeexpr(l, init);
                t = n->type;
-               fn = syslook("makeslice", 1);
-               argtype(fn, t->type);                   // any-1
-               n = mkcall1(fn, n->type, init,
-                       typename(n->type),
-                       conv(l, types[TINT64]),
-                       conv(r, types[TINT64]));
+               if(n->esc == EscNone
+                       && smallintconst(l) && smallintconst(r)
+                       && mpgetfix(r->val.u.xval) < (1ULL<<16) / t->type->width) {
+                       // var arr [r]T
+                       // n = arr[:l]
+                       t = aindex(r, t->type); // [r]T
+                       var = temp(t);
+                       a = nod(OAS, var, N); // zero temp
+                       typecheck(&a, Etop);
+                       *init = list(*init, a);
+                       r = nod(OSLICE, var, nod(OKEY, N, l)); // arr[:l]
+                       r = conv(r, n->type); // in case n->type is named.
+                       typecheck(&r, Erv);
+                       walkexpr(&r, init);
+                       n = r;
+               } else {
+                       // makeslice(t *Type, nel int64, max int64) (ary []any)
+                       fn = syslook("makeslice", 1);
+                       argtype(fn, t->type);                   // any-1
+                       n = mkcall1(fn, n->type, init,
+                               typename(n->type),
+                               conv(l, types[TINT64]),
+                               conv(r, types[TINT64]));
+               }
                goto ret;
 
        case ORUNESTR: