◐ Shell
reader mode source ↗
Skip to content
Merged
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
29 changes: 20 additions & 9 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2796,6 +2796,11 @@ class NonExistingFilesCache {
m_pathSet.insert(path);
}

private:
std::set<std::string> m_pathSet;
CRITICAL_SECTION m_criticalSection;
Expand All @@ -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);
if (nonExistingFilesCache.contains(simplePath))
return ""; // file is known not to exist, skip expensive file open call

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) : "";
#endif
}

static std::string getRelativeFileName(const std::string &sourcefile, const std::string &header)
Expand Down Expand Up @@ -2907,6 +2908,11 @@ static bool hasFile(const std::map<std::string, simplecpp::TokenList *> &filedat

std::map<std::string, simplecpp::TokenList*> simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList)
{
std::map<std::string, simplecpp::TokenList*> ret;

std::list<const Token *> filelist;
Expand Down Expand Up @@ -3032,6 +3038,11 @@ static std::string getTimeDefine(struct tm *timep)

void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, simplecpp::TokenList *> &filedata, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
{
std::map<std::string, std::size_t> sizeOfType(rawtokens.sizeOfType);
sizeOfType.insert(std::make_pair("char", sizeof(char)));
sizeOfType.insert(std::make_pair("short", sizeof(short)));
Expand Down
3 changes: 2 additions & 1 deletion simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,13 @@ namespace simplecpp {
* On the command line these are configured by -D, -U, -I, --include, -std
*/
struct SIMPLECPP_LIB DUI {
DUI() {}
std::list<std::string> defines;
std::set<std::string> undefined;
std::list<std::string> includePaths;
std::list<std::string> includes;
std::string std;
};

SIMPLECPP_LIB long long characterLiteralToLL(const std::string& str);
Expand Down
Toggle all file notes Toggle all file annotations