2 ms·
I think there's some contradiction between those statements: > Rather than having, as C++ has, a complete map implementation for each unique map declaration, t
by Matthias247 8y ago
I think there's some contradiction between those statements:
> Rather than having, as C++ has, a complete map implementation for each unique map declaration, the Go compiler creates a maptype during compilation and uses that value when calling into the runtime’s map functions.
> Does the compiler use code generation?
> No, there is only one copy of the map implementation in a Go binary
The compiler certainly does code generation, as outlined in the article. It just minimizes the amount of generated code, and uses explicit non-generic functions on some higher layers. One can do the same in a generic C++ map implementation too, by delegating some of the logic into non-generic functions. It's a thing that is commonly done in manually size-optimized code. One could also hope that the compiler automatically detects some of the duplicated code between template instances, and deduplicates it.