mirror of https://github.com/rui314/chibicc
Cache file search results
This commit is contained in:
parent
86785fceb1
commit
c0f0614e6b
11
preprocess.c
11
preprocess.c
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue