diff --git a/simplecpp.cpp b/simplecpp.cpp index 2b7b8b00..bda9daf7 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; @@ -2807,22 +2812,18 @@ 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 - +#endif f.open(simplePath.c_str()); if (f.is_open()) return simplePath; - else { - nonExistingFilesCache.add(simplePath); - return ""; - } -#else - f.open(path.c_str()); - return f.is_open() ? simplecpp::simplifyPath(path) : ""; +#ifdef SIMPLECPP_WINDOWS + nonExistingFilesCache.add(simplePath); #endif + return ""; } static std::string getRelativeFileName(const std::string &sourcefile, const std::string &header) @@ -2907,6 +2908,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 +3038,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);