From c0f0614e6b7647fd4703abf4c455024c2ade8cd7 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/preprocess.c b/preprocess.c index de09177..e2575aa 100644 --- a/preprocess.c +++ b/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; }