array: fix multiple array.repeat index error
parent
827a9e221f
commit
b4ad174b7f
|
@ -119,7 +119,14 @@ pub fn (a array) repeat(count int) array {
|
|||
cap: count * a.len
|
||||
}
|
||||
for i in 0..count {
|
||||
C.memcpy(byteptr(arr.data) + i * a.len * a.element_size, byteptr(a.data), a.len * a.element_size)
|
||||
if a.len > 0 && a.element_size == sizeof(array) {
|
||||
ary := array{}
|
||||
C.memcpy(&ary, a.data, sizeof(array))
|
||||
ary_clone := ary.clone()
|
||||
C.memcpy(byteptr(arr.data) + i * a.len * a.element_size, &ary_clone, a.len * a.element_size)
|
||||
} else {
|
||||
C.memcpy(byteptr(arr.data) + i * a.len * a.element_size, byteptr(a.data), a.len * a.element_size)
|
||||
}
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
|
|
@ -821,4 +821,8 @@ fn test_mutli_array_index() {
|
|||
mut a := [][]int{len:2, init: []int{len:3, init:0}}
|
||||
a[0][0] = 1
|
||||
assert '$a' == '[[1, 0, 0], [0, 0, 0]]'
|
||||
|
||||
mut b := [[0].repeat(3)].repeat(2)
|
||||
b[0][0] = 1
|
||||
assert '$b' == '[[1, 0, 0], [0, 0, 0]]'
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue