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

builtin: simplify copy/2

This commit is contained in:
Delyan Angelov 2021-03-02 18:14:42 +02:00
parent d0e8e8f178
commit 488848e904
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -532,13 +532,11 @@ pub fn (b []byte) hex() string {
// Returns the number of elements copied.
// TODO: implement for all types
pub fn copy(dst []byte, src []byte) int {
if dst.len > 0 && src.len > 0 {
mut min := 0
min = if dst.len < src.len { dst.len } else { src.len }
unsafe { C.memcpy(byteptr(dst.data), src[..min].data, dst.element_size * min) }
return min
min := if dst.len < src.len { dst.len } else { src.len }
if min > 0 {
unsafe { C.memcpy(byteptr(dst.data), src.data, min) }
}
return 0
return min
}
// Private function. Comparator for int type.