Thanks! That clarifies a few things. Too bad this isn't covered in the blog post which was specifically about how Go implements maps efficiently. Here are two interesting things the post doesn't cover:
1) How the insert works and why it's this way instead of any other;
2) Apparently the runtime has specialized implementations to insert values for some key types (string in this case), which implies it does in fact have multiple implementations of the "same" code.
Edit: I'm also curious how plain Go code can assign a value directly to an unsafe pointer without expressing the type? Or is that made unnecessary because the compiler rewrites the `myMap["key"] = value` step and has free reign to output unsafe, untyped Go code that isn't normally valid?
yeah. my guess is the compiler just outputs its intermediate format when it sees map assignment and can just do whatever it wants.
for reference you can play around with this by doing:
go build test.go
go tool objdump ./test
then search for test.go in the output and you should be able to find the go 'assembly' for your functions. also, if you use a big enough struct type then go will call into a memcpy() style routine to do the assignment.
so for this it does:
so its kind of like: EDIT: oops confused 0x3 with the value the first time around