From f5977e1bffde65c8ef7daa8d05e0921b61bb56e8 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 19 Sep 2020 21:04:38 +0900 Subject: [PATCH] Cache file search results --- preprocess.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/preprocess.c b/preprocess.c index 3f42b87..a09ba6a 100644 --- a/preprocess.c +++ b/preprocess.c @@ -701,11 +701,18 @@ bool file_exists(char *path) { } 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. for (int i = 0; i < include_paths.len; i++) { 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 NULL; } -- GitLab