1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

arrays: add generic copy fn (#13677)

This commit is contained in:
Nick Treleaven
2022-03-08 07:44:04 +00:00
committed by GitHub
parent beb1b8ce1b
commit 17fcc788f2
3 changed files with 31 additions and 2 deletions

View File

@ -815,11 +815,11 @@ pub fn (b []byte) hex() string {
// The number of the elements copied is the minimum of the length of both arrays.
// Returns the number of elements copied.
// NOTE: This is not an `array` method. It is a function that takes two arrays of bytes.
// TODO: implement for all types
// See also: `arrays.copy`.
pub fn copy(dst []byte, src []byte) int {
min := if dst.len < src.len { dst.len } else { src.len }
if min > 0 {
unsafe { vmemcpy(&byte(dst.data), src.data, min) }
unsafe { vmemmove(&byte(dst.data), src.data, min) }
}
return min
}