From e5721030ca58eaa14da2a8d78a09ceb24a602b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 17 Dec 2022 09:13:31 +0100 Subject: [PATCH] greatly sped up `dmake` (#4630) * dmake.cpp: use `endsWith()` in `getCppFiles()` * dmake.cpp: optimized string concatenation in `getDeps()` * dmake.cpp: avoid duplicated `std::string::find()` in `getDeps()` * dmake.cpp: no need to get dependencies of headers without `.h` extension in `getDeps()` * dmake.cpp: do not try to look for file in `externals` folder which does not contain any headers in `getDeps()` --- Makefile | 2 +- tools/dmake.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index c9d6e5d98..89bb74cd6 100644 --- a/Makefile +++ b/Makefile @@ -852,6 +852,6 @@ externals/simplecpp/simplecpp.o: externals/simplecpp/simplecpp.cpp externals/sim externals/tinyxml2/tinyxml2.o: externals/tinyxml2/tinyxml2.cpp externals/tinyxml2/tinyxml2.h $(CXX) $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ externals/tinyxml2/tinyxml2.cpp -tools/dmake.o: tools/dmake.cpp cli/filelister.h lib/config.h lib/pathmatch.h +tools/dmake.o: tools/dmake.cpp cli/filelister.h lib/config.h lib/pathmatch.h lib/utils.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ tools/dmake.cpp diff --git a/tools/dmake.cpp b/tools/dmake.cpp index 29e70e385..a6644f301 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -27,6 +27,7 @@ #include "../cli/filelister.h" #include "../lib/pathmatch.h" +#include "../lib/utils.h" static std::string builddir(std::string filename) { @@ -56,7 +57,7 @@ static std::string objfiles(const std::vector &files) static void getDeps(const std::string &filename, std::vector &depfiles) { - static const std::array externalfolders{"externals", "externals/picojson", "externals/simplecpp", "externals/tinyxml2"}; + static const std::array externalfolders{"externals/picojson", "externals/simplecpp", "externals/tinyxml2"}; // Is the dependency already included? if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end()) @@ -102,10 +103,15 @@ static void getDeps(const std::string &filename, std::vector &depfi pos1 += 10; const std::string::size_type pos2 = line.find(rightBracket, pos1); - std::string hfile = path + line.substr(pos1, pos2 - pos1); + std::string hfile(path); + hfile += line.substr(pos1, pos2 - pos1); - if (hfile.find("/../") != std::string::npos) // TODO: Ugly fix - hfile.erase(0, 4 + hfile.find("/../")); + const std::string::size_type traverse_pos = hfile.find("/../"); + if (traverse_pos != std::string::npos) // TODO: Ugly fix + hfile.erase(0, 4 + traverse_pos); + // no need to look up extension-less headers + if (!endsWith(hfile, ".h")) + continue; getDeps(hfile, depfiles); } } @@ -136,7 +142,7 @@ static std::string getCppFiles(std::vector &files, const std::strin // add *.cpp files to the "files" vector.. for (const std::pair file : filemap) { - if (file.first.find(".cpp") != std::string::npos) + if (endsWith(file.first, ".cpp")) files.push_back(file.first); } return "";