From e5b0478e19fede5f8f6729d3b5fb0a11399709b5 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Mon, 14 Oct 2019 12:07:59 +1100 Subject: [PATCH] compiler: optimize, don't rescan module directory for files (#2334) * optimize, don't rescan module directory for files * move from table to v --- vlib/compiler/main.v | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 0a3125d4dd..10f7ff0fee 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -574,7 +574,6 @@ pub fn (v mut V) add_v_files_to_compile() { // main files will get added last continue } - // use cached built module if exists if v.pref.build_mode != .build_module && !mod.contains('vweb') { mod_path := mod.replace('.', os.path_separator) @@ -587,8 +586,7 @@ pub fn (v mut V) add_v_files_to_compile() { } } // standard module - mod_path := v.find_module_path(mod) or { verror(err) break } - vfiles := v.v_files_from_dir(mod_path) + vfiles := v.get_imported_module_files(mod) for file in vfiles { v.files << file } @@ -633,7 +631,7 @@ pub fn (v &V) get_user_files() []string { if dir.ends_with('.v') { // Just compile one file and get parent dir user_files << dir - dir = dir.all_before('${os.path_separator}') + dir = dir.all_before(os.path_separator) } else { // Add .v files from the directory being compiled @@ -653,6 +651,17 @@ pub fn (v &V) get_user_files() []string { return user_files } +// get module files from already parsed imports +fn (v &V) get_imported_module_files(mod string) []string { + mut files := []string + for _, fit in v.table.file_imports { + if fit.module_name == mod { + files << fit.file_path_id + } + } + return files +} + // parse deps from already parsed builtin/user files pub fn (v mut V) parse_lib_imports() { mut done_fits := []string