1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

compiler: optimize mark_var_used() etc

This commit is contained in:
Alexander Medvednikov
2019-09-23 22:47:09 +03:00
parent 8d52d877fb
commit f27f3515ae
4 changed files with 26 additions and 19 deletions

View File

@@ -69,27 +69,24 @@ fn (p mut Parser) open_scope() {
}
fn (p mut Parser) mark_var_used(v Var) {
for i, vv in p.local_vars {
if vv.name == v.name {
p.local_vars[i].is_used = true
}
}
if v.idx == -1 {
return
}
p.local_vars[v.idx].is_used = true
}
fn (p mut Parser) mark_var_returned(v Var) {
for i, vv in p.local_vars {
if vv.name == v.name {
p.local_vars[i].is_returned = true
}
}
if v.idx == -1 || v.idx >= p.local_vars.len {
return
}
p.local_vars[v.idx].is_returned = true
}
fn (p mut Parser) mark_var_changed(v Var) {
for i, vv in p.local_vars {
if vv.name == v.name {
p.local_vars[i].is_changed = true
}
}
if v.idx == -1 || v.idx >= p.local_vars.len {
return
}
p.local_vars[v.idx].is_changed = true
}
fn (p mut Parser) known_var(name string) bool {
@@ -100,7 +97,7 @@ fn (p mut Parser) known_var(name string) bool {
}
fn (p mut Parser) register_var(v Var) {
mut new_var := {v | scope_level: p.cur_fn.scope_level}
mut new_var := {v | idx: p.var_idx, scope_level: p.cur_fn.scope_level}
if v.line_nr == 0 {
spos := p.scanner.get_scanner_pos()
new_var.scanner_pos = spos