cgen: dont preallocate zero length with capacity of 1
parent
cf07375d1b
commit
560301dbfe
|
@ -95,13 +95,11 @@ fn (mut a array) ensure_cap(required int) {
|
|||
cap *= 2
|
||||
}
|
||||
new_size := cap * a.element_size
|
||||
mut new_data := &byte(0)
|
||||
if a.data != voidptr(0) {
|
||||
new_data = unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) }
|
||||
a.data = if a.data != voidptr(0) {
|
||||
unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) }
|
||||
} else {
|
||||
new_data = vcalloc(new_size)
|
||||
vcalloc(new_size)
|
||||
}
|
||||
a.data = new_data
|
||||
a.cap = cap
|
||||
}
|
||||
|
||||
|
|
|
@ -5978,7 +5978,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
|
|||
elem_type_str = elem_type_str[3..]
|
||||
}
|
||||
noscan := g.check_noscan(elem_typ)
|
||||
init_str := '__new_array${noscan}(0, 1, sizeof($elem_type_str))'
|
||||
init_str := '__new_array${noscan}(0, 0, sizeof($elem_type_str))'
|
||||
if typ.has_flag(.shared_f) {
|
||||
atyp := '__shared__Array_${g.table.get_type_symbol(elem_typ).cname}'
|
||||
return '($atyp*)__dup_shared_array(&($atyp){.mtx = {0}, .val =$init_str}, sizeof($atyp))'
|
||||
|
|
Loading…
Reference in New Issue