Open
Description
What does 'go version' print? go version go1.3 linux/amd64 What steps reproduce the problem? Using the 2-return 'range' over a slice of structs will copy each struct, even if the struct is provably not modified in the loop. This is a premature pessimization that the compiler could and should eliminate. Ideally the spec would guarantee this optimization (a la RVO in C++) so people could count on it and maybe even warn when it is not true. The for-each construct is much nicer to read and write, but this behavior sort of makes it a non-starter for large data. This is discussed in many places on the web, with the general recommendation of "just iterate on index". This is unfortunate for the language. Alternatively: some syntax to say explicitly "iterate by reference" or by pointer. Ian asked me to file this issue.