mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: eliminate the usage of _us32_eq for frequent builtin array operations
This commit is contained in:
parent
fee56b1902
commit
ff93e8afee
@ -116,10 +116,11 @@ pub fn (a array) repeat(count int) array {
|
|||||||
len: count * a.len
|
len: count * a.len
|
||||||
cap: count * a.len
|
cap: count * a.len
|
||||||
}
|
}
|
||||||
|
size_of_array := int(sizeof(array))
|
||||||
for i in 0 .. count {
|
for i in 0 .. count {
|
||||||
if a.len > 0 && a.element_size == sizeof(array) {
|
if a.len > 0 && a.element_size == size_of_array {
|
||||||
ary := array{}
|
ary := array{}
|
||||||
unsafe {C.memcpy(&ary, a.data, sizeof(array))}
|
unsafe {C.memcpy(&ary, a.data, size_of_array)}
|
||||||
ary_clone := ary.clone()
|
ary_clone := ary.clone()
|
||||||
unsafe {C.memcpy(arr.get_unsafe(i * a.len), &ary_clone, a.len * a.element_size)}
|
unsafe {C.memcpy(arr.get_unsafe(i * a.len), &ary_clone, a.len * a.element_size)}
|
||||||
} else {
|
} else {
|
||||||
@ -328,10 +329,11 @@ pub fn (a &array) clone() array {
|
|||||||
cap: a.cap
|
cap: a.cap
|
||||||
}
|
}
|
||||||
// Recursively clone-generated elements if array element is array type
|
// Recursively clone-generated elements if array element is array type
|
||||||
if a.element_size == sizeof(array) {
|
size_of_array := int(sizeof(array))
|
||||||
|
if a.element_size == size_of_array {
|
||||||
for i in 0 .. a.len {
|
for i in 0 .. a.len {
|
||||||
ar := array{}
|
ar := array{}
|
||||||
unsafe {C.memcpy(&ar, a.get_unsafe(i), sizeof(array))}
|
unsafe {C.memcpy(&ar, a.get_unsafe(i), size_of_array)}
|
||||||
ar_clone := ar.clone()
|
ar_clone := ar.clone()
|
||||||
unsafe {arr.set_unsafe(i, &ar_clone)}
|
unsafe {arr.set_unsafe(i, &ar_clone)}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user