mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: dont preallocate zero length with capacity of 1
This commit is contained in:
parent
cf07375d1b
commit
560301dbfe
@ -95,13 +95,11 @@ fn (mut a array) ensure_cap(required int) {
|
|||||||
cap *= 2
|
cap *= 2
|
||||||
}
|
}
|
||||||
new_size := cap * a.element_size
|
new_size := cap * a.element_size
|
||||||
mut new_data := &byte(0)
|
a.data = if a.data != voidptr(0) {
|
||||||
if a.data != voidptr(0) {
|
unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) }
|
||||||
new_data = unsafe { realloc_data(a.data, a.cap * a.element_size, new_size) }
|
|
||||||
} else {
|
} else {
|
||||||
new_data = vcalloc(new_size)
|
vcalloc(new_size)
|
||||||
}
|
}
|
||||||
a.data = new_data
|
|
||||||
a.cap = cap
|
a.cap = cap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5978,7 +5978,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
|
|||||||
elem_type_str = elem_type_str[3..]
|
elem_type_str = elem_type_str[3..]
|
||||||
}
|
}
|
||||||
noscan := g.check_noscan(elem_typ)
|
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) {
|
if typ.has_flag(.shared_f) {
|
||||||
atyp := '__shared__Array_${g.table.get_type_symbol(elem_typ).cname}'
|
atyp := '__shared__Array_${g.table.get_type_symbol(elem_typ).cname}'
|
||||||
return '($atyp*)__dup_shared_array(&($atyp){.mtx = {0}, .val =$init_str}, sizeof($atyp))'
|
return '($atyp*)__dup_shared_array(&($atyp){.mtx = {0}, .val =$init_str}, sizeof($atyp))'
|
||||||
|
Loading…
Reference in New Issue
Block a user