Skip to content

Commit d2f5d34

Browse files
rsBNTdanmar
authored andcommitted
Improve performance on windows (#110)
* use faster WIN API if possible * return early if nothing searchable exists * remove conversion to vector of char because const char* (via c_str()) is LPCSTR * implement common (http://en.cppreference.com/w/cpp/filesystem/path step 1) quick return part of algo for empty paths * couldnt find any performance diff with FIND_FIRST_EX_LARGE_FETCH so took the check for OS version out because all other OS support the call with NULL. Also removes need for static * cleanup
1 parent 2425abc commit d2f5d34

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

simplecpp.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,15 +1745,11 @@ static bool realFileName(const std::string &f, std::string *result)
17451745
if (!alpha)
17461746
return false;
17471747

1748-
// Convert char path to CHAR path
1749-
std::vector<CHAR> buf(f.size()+1U, 0);
1750-
for (unsigned int i = 0; i < f.size(); ++i)
1751-
buf[i] = f[i];
1752-
17531748
// Lookup filename or foldername on file system
17541749
WIN32_FIND_DATAA FindFileData;
1755-
HANDLE hFind = FindFirstFileA(&buf[0], &FindFileData);
1756-
if (hFind == INVALID_HANDLE_VALUE)
1750+
HANDLE hFind = FindFirstFileExA(f.c_str(), FindExInfoBasic, &FindFileData, FindExSearchNameMatch, NULL, 0);
1751+
1752+
if (INVALID_HANDLE_VALUE == hFind)
17571753
return false;
17581754
*result = FindFileData.cFileName;
17591755
FindClose(hFind);
@@ -1828,6 +1824,9 @@ namespace simplecpp {
18281824
*/
18291825
std::string simplifyPath(std::string path)
18301826
{
1827+
if (path.empty())
1828+
return path;
1829+
18311830
std::string::size_type pos;
18321831

18331832
// replace backslash separators
@@ -2023,6 +2022,9 @@ static std::string openHeader(std::ifstream &f, const simplecpp::DUI &dui, const
20232022

20242023
static std::string getFileName(const std::map<std::string, simplecpp::TokenList *> &filedata, const std::string &sourcefile, const std::string &header, const simplecpp::DUI &dui, bool systemheader)
20252024
{
2025+
if (filedata.empty()) {
2026+
return "";
2027+
}
20262028
if (isAbsolutePath(header)) {
20272029
return (filedata.find(header) != filedata.end()) ? simplecpp::simplifyPath(header) : "";
20282030
}

0 commit comments

Comments
 (0)