]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: don't use static init to initialize small structs, fields
authorRuss Cox <rsc@golang.org>
Fri, 17 Oct 2014 17:10:42 +0000 (13:10 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 17 Oct 2014 17:10:42 +0000 (13:10 -0400)
Better to avoid the memory loads and just use immediate constants.
This especially applies to zeroing, which was being done by
copying zeros from elsewhere in the binary, even if the value
was going to be completely initialized with non-zero values.
The zero writes were optimized away but the zero loads from
the data segment were not.

LGTM=r
R=r, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/152700045

src/cmd/gc/sinit.c

index 2a811513c9b3e257f43e81b13f2d65fe71214e5f..8ad7ae7abb3a6264e7bb66818305f0abc3036833 100644 (file)
@@ -1067,7 +1067,7 @@ anylit(int ctxt, Node *n, Node *var, NodeList **init)
                if(t->etype != TSTRUCT)
                        fatal("anylit: not struct");
 
-               if(simplename(var)) {
+               if(simplename(var) && count(n->list) > 4) {
 
                        if(ctxt == 0) {
                                // lay out static data
@@ -1090,7 +1090,7 @@ anylit(int ctxt, Node *n, Node *var, NodeList **init)
                }
 
                // initialize of not completely specified
-               if(count(n->list) < structcount(t)) {
+               if(simplename(var) || count(n->list) < structcount(t)) {
                        a = nod(OAS, var, N);
                        typecheck(&a, Etop);
                        walkexpr(&a, init);
@@ -1107,7 +1107,7 @@ anylit(int ctxt, Node *n, Node *var, NodeList **init)
                        break;
                }
 
-               if(simplename(var)) {
+               if(simplename(var) && count(n->list) > 4) {
 
                        if(ctxt == 0) {
                                // lay out static data
@@ -1130,7 +1130,7 @@ anylit(int ctxt, Node *n, Node *var, NodeList **init)
                }
 
                // initialize of not completely specified
-               if(count(n->list) < t->bound) {
+               if(simplename(var) || count(n->list) < t->bound) {
                        a = nod(OAS, var, N);
                        typecheck(&a, Etop);
                        walkexpr(&a, init);