v: reduce the memory usage of the compiler (analysed with heaptrack)

pull/10024/head
Delyan Angelov 2021-05-06 11:44:48 +03:00
parent 84f9789e72
commit 2eafea6308
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 13 additions and 7 deletions

View File

@ -742,7 +742,7 @@ pub fn (s string) index(p string) ?int {
}
// index_kmp does KMP search.
[manualfree]
[direct_array_access; manualfree]
fn (s string) index_kmp(p string) int {
if p.len > s.len {
return -1

View File

@ -14,8 +14,8 @@ fn nr_next(prev u32) u32 {
// time_seed_array returns the required number of u32s generated from system time.
[inline]
pub fn time_seed_array(count int) []u32 {
ctime := time.now()
mut seed := u32(ctime.unix_time() ^ ctime.microsecond)
ctime := time.sys_mono_now()
mut seed := u32(ctime >> 32 ^ (ctime & 0x0000_0000_FFFF_FFFF))
mut seed_data := []u32{cap: count}
for _ in 0 .. count {
seed = nr_next(seed)

View File

@ -764,12 +764,12 @@ pub fn (mut t Table) find_or_register_thread(return_type Type) int {
pub fn (mut t Table) find_or_register_array(elem_type Type) int {
name := t.array_name(elem_type)
cname := t.array_cname(elem_type)
// existing
existing_idx := t.type_idxs[name]
if existing_idx > 0 {
return existing_idx
}
cname := t.array_cname(elem_type)
// register
array_type_ := TypeSymbol{
parent_idx: array_type_idx

View File

@ -5231,10 +5231,16 @@ fn (mut g Gen) struct_init(struct_init ast.StructInit) {
}
// g.zero_struct_fields(info, inited_fields)
// nr_fields = info.fields.len
for field in info.fields {
for mut field in info.fields {
if mut sym.info is ast.Struct {
equal_fields := sym.info.fields.filter(it.name == field.name)
if equal_fields.len == 0 {
mut found_equal_fields := 0
for mut sifield in sym.info.fields {
if sifield.name == field.name {
found_equal_fields++
break
}
}
if found_equal_fields == 0 {
continue
}
}