mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vlib: add mut
for the first parameter of builtin.copy, arrays.copy and crypto (#13702)
This commit is contained in:
@@ -544,7 +544,7 @@ fn swap_nonoverlapping<T>(x_ &T, y_ &T, count int) {
|
||||
// copy copies the `src` array elements to the `dst` array.
|
||||
// The number of the elements copied is the minimum of the length of both arrays.
|
||||
// Returns the number of elements copied.
|
||||
pub fn copy<T>(dst []T, src []T) int {
|
||||
pub fn copy<T>(mut dst []T, src []T) int {
|
||||
min := if dst.len < src.len { dst.len } else { src.len }
|
||||
if min > 0 {
|
||||
blen := min * int(sizeof(T))
|
||||
|
@@ -268,16 +268,16 @@ fn test_rotate_left_string() {
|
||||
fn test_copy() {
|
||||
mut a := [1, 2, 3]
|
||||
mut b := [4, 5, 6]
|
||||
assert copy(b, a) == 3
|
||||
assert copy(mut b, a) == 3
|
||||
assert b == [1, 2, 3]
|
||||
// check independent copies
|
||||
b[0] = 99
|
||||
assert a[0] == 1
|
||||
// check longer src
|
||||
b << 7
|
||||
assert copy(a, b) == 3
|
||||
assert copy(mut a, b) == 3
|
||||
assert a == [99, 2, 3]
|
||||
// check longer dst
|
||||
assert copy(b, [8, 9]) == 2
|
||||
assert copy(mut b, [8, 9]) == 2
|
||||
assert b == [8, 9, 3, 7]
|
||||
}
|
||||
|
Reference in New Issue
Block a user