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

arrays: move carray_to_varray from builtin, make it generic (#15503)

This commit is contained in:
Larpon
2022-08-23 10:12:50 +02:00
committed by GitHub
parent 2dde7ff5ba
commit 9dd8228f91
4 changed files with 31 additions and 12 deletions

View File

@ -126,15 +126,6 @@ fn new_array_from_c_array_no_alloc(len int, cap int, elm_size int, c_array voidp
return arr
}
// carray_to_varray copies a C byte array into a V `u8` array.
// See also: `cstring_to_vstring`
[unsafe]
pub fn carray_to_varray(c_array voidptr, c_array_len int) []u8 {
mut v_array := []u8{len: c_array_len}
unsafe { vmemcpy(v_array.data, c_array, c_array_len * int(sizeof(u8))) }
return v_array
}
// Private function. Increases the `cap` of an array to the
// required value by copying the data to a new memory location
// (creating a clone) unless `a.cap` is already large enough.