]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix special-casing of the printed names of map internal structures.
authorKeith Randall <khr@golang.org>
Tue, 3 Dec 2013 22:27:08 +0000 (14:27 -0800)
committerKeith Randall <khr@golang.org>
Tue, 3 Dec 2013 22:27:08 +0000 (14:27 -0800)
Shaves 1% off of binary size.

update #6853

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/35940047

src/cmd/gc/fmt.c
src/cmd/gc/go.h
src/cmd/gc/reflect.c

index afa9d8020c0f89bd69f8f4f288cde27a7ff8a175..576017e8b7de8f6dcbb57f6cc12db11c97247939 100644 (file)
@@ -702,13 +702,17 @@ typefmt(Fmt *fp, Type *t)
        case TSTRUCT:
                // Format the bucket struct for map[x]y as map.bucket[x]y.
                // This avoids a recursive print that generates very long names.
-               if(t->hmap != T) {
-                       t = t->hmap;
-                       return fmtprint(fp, "map.bucket[%T]%T", t->down, t->type);
-               }
-               if(t->hiter != T) {
-                       t = t->hiter;
-                       return fmtprint(fp, "map.iter[%T]%T", t->down, t->type);
+               if(t->map != T) {
+                       if(t->map->bucket == t) {
+                               return fmtprint(fp, "map.bucket[%T]%T", t->map->down, t->map->type);
+                       }
+                       if(t->map->hmap == t) {
+                               return fmtprint(fp, "map.hdr[%T]%T", t->map->down, t->map->type);
+                       }
+                       if(t->map->hiter == t) {
+                               return fmtprint(fp, "map.iter[%T]%T", t->map->down, t->map->type);
+                       }
+                       yyerror("unknown internal map type");
                }
 
                if(t->funarg) {
index 5bf3068175a03eb1b9156b5d9e30daca056e902a..821f30492e933ca9e3e3bda19e7c2860f9baa1b9 100644 (file)
@@ -191,6 +191,7 @@ struct      Type
        Type*   bucket;         // internal type representing a hash bucket
        Type*   hmap;           // internal type representing a Hmap (map header object)
        Type*   hiter;          // internal type representing hash iterator state
+       Type*   map;            // link from the above 3 internal types back to the map type.
 
        int32   maplineno;      // first use of TFORW as map key
        int32   embedlineno;    // first use of TFORW as embedded type
index 1097d152195bc2e5aa3a6a5f0128313ade7a0412..9e4c07252316bf6ac3d9c5ff0f21de9f64cd4488 100644 (file)
@@ -173,6 +173,7 @@ mapbucket(Type *t)
        bucket->width = offset;
        bucket->local = t->local;
        t->bucket = bucket;
+       bucket->map = t;
        return bucket;
 }
 
@@ -229,7 +230,7 @@ hmap(Type *t)
        h->width = offset;
        h->local = t->local;
        t->hmap = h;
-       h->hmap = t;
+       h->map = t;
        return h;
 }
 
@@ -308,7 +309,7 @@ hiter(Type *t)
        if(off != 11 * widthptr)
                yyerror("hash_iter size not correct %d %d", off, 11 * widthptr);
        t->hiter = i;
-       i->hiter = t;
+       i->map = t;
        return i;
 }