Skip to content

Commit f238049

Browse files
committed
cmd/gc: fix special-casing of the printed names of map internal structures.
Shaves 1% off of binary size. update #6853 R=golang-dev, rsc CC=golang-dev https://golang.org/cl/35940047
1 parent 0368a7c commit f238049

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/cmd/gc/fmt.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,17 @@ typefmt(Fmt *fp, Type *t)
702702
case TSTRUCT:
703703
// Format the bucket struct for map[x]y as map.bucket[x]y.
704704
// This avoids a recursive print that generates very long names.
705-
if(t->hmap != T) {
706-
t = t->hmap;
707-
return fmtprint(fp, "map.bucket[%T]%T", t->down, t->type);
708-
}
709-
if(t->hiter != T) {
710-
t = t->hiter;
711-
return fmtprint(fp, "map.iter[%T]%T", t->down, t->type);
705+
if(t->map != T) {
706+
if(t->map->bucket == t) {
707+
return fmtprint(fp, "map.bucket[%T]%T", t->map->down, t->map->type);
708+
}
709+
if(t->map->hmap == t) {
710+
return fmtprint(fp, "map.hdr[%T]%T", t->map->down, t->map->type);
711+
}
712+
if(t->map->hiter == t) {
713+
return fmtprint(fp, "map.iter[%T]%T", t->map->down, t->map->type);
714+
}
715+
yyerror("unknown internal map type");
712716
}
713717

714718
if(t->funarg) {

src/cmd/gc/go.h

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ struct Type
191191
Type* bucket; // internal type representing a hash bucket
192192
Type* hmap; // internal type representing a Hmap (map header object)
193193
Type* hiter; // internal type representing hash iterator state
194+
Type* map; // link from the above 3 internal types back to the map type.
194195

195196
int32 maplineno; // first use of TFORW as map key
196197
int32 embedlineno; // first use of TFORW as embedded type

src/cmd/gc/reflect.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ mapbucket(Type *t)
173173
bucket->width = offset;
174174
bucket->local = t->local;
175175
t->bucket = bucket;
176+
bucket->map = t;
176177
return bucket;
177178
}
178179

@@ -229,7 +230,7 @@ hmap(Type *t)
229230
h->width = offset;
230231
h->local = t->local;
231232
t->hmap = h;
232-
h->hmap = t;
233+
h->map = t;
233234
return h;
234235
}
235236

@@ -308,7 +309,7 @@ hiter(Type *t)
308309
if(off != 11 * widthptr)
309310
yyerror("hash_iter size not correct %d %d", off, 11 * widthptr);
310311
t->hiter = i;
311-
i->hiter = t;
312+
i->map = t;
312313
return i;
313314
}
314315

0 commit comments

Comments
 (0)