Skip to content
Snippets Groups Projects
Commit f5977e1b authored by Rui Ueyama's avatar Rui Ueyama
Browse files

Cache file search results

parent 4a45be0e
Branches
No related merge requests found
...@@ -701,11 +701,18 @@ bool file_exists(char *path) { ...@@ -701,11 +701,18 @@ bool file_exists(char *path) {
} }
char *search_include_paths(char *filename) { char *search_include_paths(char *filename) {
static HashMap cache;
char *cached = hashmap_get(&cache, filename);
if (cached)
return cached;
// Search a file from the include paths. // Search a file from the include paths.
for (int i = 0; i < include_paths.len; i++) { for (int i = 0; i < include_paths.len; i++) {
char *path = format("%s/%s", include_paths.data[i], filename); char *path = format("%s/%s", include_paths.data[i], filename);
if (file_exists(path)) if (file_exists(path)) {
hashmap_put(&cache, filename, path);
return path; return path;
}
} }
return NULL; return NULL;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment