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

builtin, checker, cgen: implement x = a[k] or { ... } for maps and arrays (#8193)

This commit is contained in:
Uwe Krüger
2021-01-19 06:06:57 +01:00
committed by GitHub
parent a65b73d3e4
commit b74690cbec
5 changed files with 152 additions and 31 deletions

View File

@ -229,6 +229,16 @@ fn (a array) get(i int) voidptr {
}
}
// Private function. Used to implement x = a[i] or { ... }
fn (a array) get_with_check(i int) voidptr {
if i < 0 || i >= a.len {
return 0
}
unsafe {
return byteptr(a.data) + i * a.element_size
}
}
// first returns the first element of the array.
pub fn (a array) first() voidptr {
$if !no_bounds_checking ? {