From 488848e904462ec3ece1289e5131f99e6e38d548 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 2 Mar 2021 18:14:42 +0200 Subject: [PATCH] builtin: simplify copy/2 --- vlib/builtin/array.v | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 7b93ec0641..068343b710 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -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.