should use copy(to, from) instead of a loop
18}
19
20func imageCopyA(src []image.Image, dst []image.Image) {
21 for i, img := range src {22 dst[i] = img
23 }
24}
Description
Use copy
for copying slices instead of manually copying the elements in a
loop.
The built-in function copy
assist in common slice operations. The function
copy
copies slice elements from a source src
to a destination dst
and
returns the number of elements copied. Note that the number of elements copied
is the minimum of len(src)
and len(dst)
. Therefore, to copy all the slice
elements from src
to dst
, dst
must satisfy len(dst) >= len(src)
.
copy(dst, src []T) int
Bad practice
for i, elem := range src {
dst[i] = elem
}
Recommended
copy(dst, src)