Skip to content

Commit

Permalink
keep arrays as faster alternative to lookup maps
Browse files Browse the repository at this point in the history
tested with new tool
  • Loading branch information
ttytm committed Apr 2, 2024
1 parent 27dee18 commit ddfe323
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ pub mut:
single_line_if bool
cur_mod string
did_imports bool
import_pos int // position of the imports in the resulting string for later autoimports insertion
auto_imports map[string]bool // potentially hidden imports(`sync` when using channels) and preludes(when embedding files)
used_imports map[string]bool // to remove unused imports
import_pos int // position of the imports in the resulting string for later autoimports insertion
auto_imports []string // potentially hidden imports(`sync` when using channels) and preludes(when embedding files)
used_imports []string // to remove unused imports
import_syms_used map[string]bool // to remove unused import symbols
mod2alias map[string]string // for `import time as t`, will contain: 'time'=>'t'
mod2syms map[string]string // import time { now } 'time.now'=>'now'
Expand Down Expand Up @@ -112,9 +112,7 @@ pub fn (mut f Fmt) process_file_imports(file &ast.File) {
f.import_syms_used[sym.name] = false
}
}
for mod in f.file.auto_imports {
f.auto_imports[mod] = true
}
f.auto_imports = file.auto_imports
}

//=== Basic buffer write operations ===//
Expand Down Expand Up @@ -319,8 +317,8 @@ pub fn (mut f Fmt) mark_types_import_as_used(typ ast.Type) {
pub fn (mut f Fmt) mark_import_as_used(name string) {
mod, sym := name.rsplit_once('.') or { '', name }
f.import_syms_used[sym] = true
if mod != '' {
f.used_imports[mod] = true
if mod != '' && mod !in f.used_imports {
f.used_imports << mod
}
}

Expand All @@ -331,7 +329,7 @@ pub fn (mut f Fmt) imports(imports []ast.Import) {
f.did_imports = true
mut processed_imports := map[string]bool{}
for imp in imports {
if !f.used_imports[imp.mod] && f.auto_imports[imp.mod] {
if imp.mod in f.auto_imports && imp.mod !in f.used_imports {
// Skip hidden imports like preludes.
continue
}
Expand Down Expand Up @@ -1954,7 +1952,9 @@ pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
mod: node.left.name
alias: node.left.name
}
f.used_imports[node.left.name] = true
if node.left.name !in f.used_imports {
f.used_imports << node.left.name
}
}
}
f.expr(node.left)
Expand Down

0 comments on commit ddfe323

Please sign in to comment.