2 ms·
To add to the sibling, you could iterate by index to avoid the copy: for i := range items { ptr := &items[i] ... } In this case of cou
by foldr 4y ago
To add to the sibling, you could iterate by index to avoid the copy:
for i := range items {
ptr := &items[i]
...
}
In this case of course you also get different semantics. The ptr variable is bound to the address of each of the original Item values in the slice, whereas in the code in your comment, &item is the address of a single heap-allocated Item variable.