Open dominikh opened 4 years ago
In case this is not already covered It also applies to m[struct{...,string(...),....}] and arrays. But that might not come up often enough.
@martisch I'm wondering, would the compiler be able to optimize m[buf.String()]
? Or does the branch in the String method make that too difficult?
@dominikh I think such an optimization would only come in the future through inlining and dead code elimination together with moving more such optimizations into the SSA backend.
The current frontend itself doesnt do these cross function optimizations and doesnt as far as I know try to give std packages semantics hardcoded in the compiler.
The optimization of
m[string(b)]
applies to bytes.Buffer, too, makingm[string(buf.Bytes())]
more efficient thanm[buf.String()]
.