Cache file search results

This commit is contained in:
Rui Ueyama 2020-09-19 21:04:38 +09:00
parent 86785fceb1
commit c0f0614e6b
1 changed files with 9 additions and 2 deletions

View File

@ -684,11 +684,18 @@ char *search_include_paths(char *filename) {
if (filename[0] == '/')
return filename;
static HashMap cache;
char *cached = hashmap_get(&cache, filename);
if (cached)
return cached;
// Search a file from the include paths.
for (int i = 0; i < include_paths.len; i++) {
char *path = format("%s/%s", include_paths.data[i], filename);
if (file_exists(path))
return path;
if (!file_exists(path))
continue;
hashmap_put(&cache, filename, path);
return path;
}
return NULL;
}