Skip to content

Commit

Permalink
Cache file search results
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Dec 7, 2020
1 parent 86785fc commit c0f0614
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions preprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c0f0614

Please sign in to comment.