it is almost always a bad idea to use append and assign the result to a 
different value than the thing you're appending to.

i.e. always do this:

ns = append(ns, foo...)

and don't do this:

bar := append(ns, foo...)

The thing is, that in that last line, like in your code, bar and ns *might* 
point to the same backing array, and they might not.   If you always assign 
an append back to the original variable, then you never have to worry 
whether a new backing array was created or not, and if not, what happens 
when you append again.

In your case, I'd just make a new slice and copy ns to it, so that you know 
what you're dealing with:

// start with 0 length and the correct capacity, so the appends just become 
copies.
ns1 := make(Namespace, 0, len(ns)+len(g2message.NamespaceWin))
ns1 = append(ns1, ns...)
ns1 = append(ns1, g2message.NamespaceWin....)

ns2 := make(Namespace, 0, len(ns)+len(g2message.NamespaceSpend))
ns2 = append(ns2, ns...)
ns2 = append(ns2, g2message.NamespaceSpend....)

-Nate

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to