1
0
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:
Joe Conigliaro
2021-05-26 14:51:20 +10:00
parent cf07375d1b
commit 560301dbfe
2 changed files with 4 additions and 6 deletions

View File

@ -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
}