From 011228f24d0ff37261de3de17a9ccbd9f50f8408 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 10 Jan 2023 15:52:56 +0100 Subject: [PATCH 1/3] added `DUI::clearIncludeCache` to clear the non-existing files cache --- simplecpp.cpp | 15 +++++++++++++++ simplecpp.h | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 2b7b8b00..a5042211 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2796,6 +2796,11 @@ class NonExistingFilesCache { m_pathSet.insert(path); } + void clear() { + ScopedLock lock(m_criticalSection); + m_pathSet.clear(); + } + private: std::set m_pathSet; CRITICAL_SECTION m_criticalSection; @@ -2907,6 +2912,11 @@ static bool hasFile(const std::map &filedat std::map simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList) { +#ifdef SIMPLECPP_WINDOWS + if (dui.clearIncludeCache) + nonExistingFilesCache .clear(); +#endif + std::map ret; std::list filelist; @@ -3032,6 +3042,11 @@ static std::string getTimeDefine(struct tm *timep) void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector &files, std::map &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list *macroUsage, std::list *ifCond) { +#ifdef SIMPLECPP_WINDOWS + if (dui.clearIncludeCache) + nonExistingFilesCache.clear(); +#endif + std::map sizeOfType(rawtokens.sizeOfType); sizeOfType.insert(std::make_pair("char", sizeof(char))); sizeOfType.insert(std::make_pair("short", sizeof(short))); diff --git a/simplecpp.h b/simplecpp.h index 24443b07..7f4b3c63 100755 --- a/simplecpp.h +++ b/simplecpp.h @@ -314,12 +314,13 @@ namespace simplecpp { * On the command line these are configured by -D, -U, -I, --include, -std */ struct SIMPLECPP_LIB DUI { - DUI() {} + DUI() : clearIncludeCache(false) {} std::list defines; std::set undefined; std::list includePaths; std::list includes; std::string std; + bool clearIncludeCache; }; SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str); From ff456f4b64a6be403e04adb3c737979c1dbca14f Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 10 Jan 2023 15:53:28 +0100 Subject: [PATCH 2/3] always simplify path in `openHeader()` --- simplecpp.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index a5042211..c7255117 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2812,8 +2812,8 @@ static NonExistingFilesCache nonExistingFilesCache; static std::string openHeader(std::ifstream &f, const std::string &path) { -#ifdef SIMPLECPP_WINDOWS std::string simplePath = simplecpp::simplifyPath(path); +#ifdef SIMPLECPP_WINDOWS if (nonExistingFilesCache.contains(simplePath)) return ""; // file is known not to exist, skip expensive file open call @@ -2825,8 +2825,8 @@ static std::string openHeader(std::ifstream &f, const std::string &path) return ""; } #else - f.open(path.c_str()); - return f.is_open() ? simplecpp::simplifyPath(path) : ""; + f.open(simplePath.c_str()); + return f.is_open() ? simplePath : ""; #endif } From 2dd210bc7c2e74e5340f63868fb6b170b631f215 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 10 Jan 2023 15:55:57 +0100 Subject: [PATCH 3/3] small `openHeader()` cleanup --- simplecpp.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index c7255117..bda9daf7 100755 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -2816,18 +2816,14 @@ static std::string openHeader(std::ifstream &f, const std::string &path) #ifdef SIMPLECPP_WINDOWS if (nonExistingFilesCache.contains(simplePath)) return ""; // file is known not to exist, skip expensive file open call - +#endif f.open(simplePath.c_str()); if (f.is_open()) return simplePath; - else { - nonExistingFilesCache.add(simplePath); - return ""; - } -#else - f.open(simplePath.c_str()); - return f.is_open() ? simplePath : ""; +#ifdef SIMPLECPP_WINDOWS + nonExistingFilesCache.add(simplePath); #endif + return ""; } static std::string getRelativeFileName(const std::string &sourcefile, const std::string &header)