builtin: simplify copy/2

pull/9069/head
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
1 changed files with 4 additions and 6 deletions

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.