Commit cfafa9f4 authored by Russ Cox's avatar Russ Cox

cmd/gc: don't use static init to initialize small structs, fields

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
parent 0d81b72e
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment