]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: unroll small array types
authorJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Fri, 15 Mar 2013 05:57:50 +0000 (06:57 +0100)
committerJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Fri, 15 Mar 2013 05:57:50 +0000 (06:57 +0100)
R=golang-dev, rsc
CC=golang-dev, nigeltao
https://golang.org/cl/7812044

src/cmd/gc/reflect.c

index b8eb79938892942c5cbaa10be122dca25fc51b89..026b5a12b52ba6974771df3c07495ed0a21f5dd6 100644 (file)
@@ -1025,11 +1025,24 @@ dalgsym(Type *t)
        return s;
 }
 
+static int
+gcinline(Type *t) {
+       switch(t->etype) {
+       case TARRAY:
+               if(t->bound == 1)
+                       return 1;
+               if(t->width <= 4*widthptr)
+                       return 1;
+               break;
+       }
+       return 0;
+}
+
 static int
 dgcsym1(Sym *s, int ot, Type *t, vlong *off, int stack_size)
 {
        Type *t1;
-       vlong o, off2, fieldoffset;
+       vlong o, off2, fieldoffset, i;
 
        if(t->align > 0 && (*off % t->align) != 0)
                fatal("dgcsym1: invalid initial alignment, %T", t);
@@ -1132,8 +1145,9 @@ dgcsym1(Sym *s, int ot, Type *t, vlong *off, int stack_size)
                } else {
                        if(t->bound < 1 || !haspointers(t->type)) {
                                *off += t->width;
-                       } else if(t->bound == 1) {
-                               ot = dgcsym1(s, ot, t->type, off, stack_size);  // recursive call of dgcsym1
+                       } else if(gcinline(t)) {
+                               for(i=0; i<t->bound; i++)
+                                       ot = dgcsym1(s, ot, t->type, off, stack_size);  // recursive call of dgcsym1
                        } else {
                                if(stack_size < GC_STACK_CAPACITY) {
                                        ot = duintptr(s, ot, GC_ARRAY_START);  // a stack push during GC