array: use __new_array everywhere

pull/4587/head
Alexander Medvednikov 2020-04-25 09:10:51 +02:00
parent fbcdffbbc8
commit 9229a963ed
2 changed files with 2 additions and 34 deletions

View File

@ -202,38 +202,6 @@ pub fn (a array) last() voidptr {
return byteptr(a.data) + (a.len - 1) * a.element_size
}
/*
// array.left returns a new array using the same buffer as the given array
// with the first `n` elements of the given array.
fn (a array) left(n int) array {
// $if !no_bounds_checking? {
// if n < 0 {
// panic('array.left: index is negative (n == $n)')
// }
// }
if n >= a.len {
return a.slice(0, a.len)
}
return a.slice(0, n)
}
// array.right returns an array using same buffer as the given array
// but starting with the element of the given array beyond the index `n`.
// If `n` is bigger or equal to the length of the given array,
// returns an empty array of the same type as the given array.
fn (a array) right(n int) array {
// $if !no_bounds_checking? {
// if n < 0 {
// panic('array.right: index is negative (n == $n)')
// }
// }
if n >= a.len {
return new_array(0, 0, a.element_size)
}
return a.slice(n, a.len)
}
*/
// array.slice returns an array using the same buffer as original array
// but starting from the `start` element and ending with the element before
// the `end` element of the original array with the length and capacity

View File

@ -2434,7 +2434,7 @@ fn (mut g Gen) gen_filter(node ast.CallExpr) {
g.write('\nint ${tmp}_len = ')
g.expr(node.left)
g.writeln('.len;')
g.writeln('$styp $tmp = new_array(0, ${tmp}_len, sizeof($elem_type_str));')
g.writeln('$styp $tmp = __new_array(0, ${tmp}_len, sizeof($elem_type_str));')
g.writeln('for (int i = 0; i < ${tmp}_len; i++) {')
g.write(' $elem_type_str it = (($elem_type_str*) ')
g.expr(node.left)
@ -2656,7 +2656,7 @@ fn (g Gen) type_default(typ table.Type) string {
if sym.kind == .array {
elem_sym := g.table.get_type_symbol(sym.array_info().elem_type)
elem_type_str := elem_sym.name.replace('.', '__')
return 'new_array(0, 1, sizeof($elem_type_str))'
return '__new_array(0, 1, sizeof($elem_type_str))'
}
if sym.kind == .map {
value_type_str := g.typ(sym.map_info().value_type)