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()`
This commit is contained in:
parent
4c8aa56d8b
commit
e5721030ca
2
Makefile
2
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
|
externals/tinyxml2/tinyxml2.o: externals/tinyxml2/tinyxml2.cpp externals/tinyxml2/tinyxml2.h
|
||||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -w -c -o $@ externals/tinyxml2/tinyxml2.cpp
|
$(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
|
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ tools/dmake.cpp
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include "../cli/filelister.h"
|
#include "../cli/filelister.h"
|
||||||
#include "../lib/pathmatch.h"
|
#include "../lib/pathmatch.h"
|
||||||
|
#include "../lib/utils.h"
|
||||||
|
|
||||||
static std::string builddir(std::string filename)
|
static std::string builddir(std::string filename)
|
||||||
{
|
{
|
||||||
|
@ -56,7 +57,7 @@ static std::string objfiles(const std::vector<std::string> &files)
|
||||||
|
|
||||||
static void getDeps(const std::string &filename, std::vector<std::string> &depfiles)
|
static void getDeps(const std::string &filename, std::vector<std::string> &depfiles)
|
||||||
{
|
{
|
||||||
static const std::array<std::string, 4> externalfolders{"externals", "externals/picojson", "externals/simplecpp", "externals/tinyxml2"};
|
static const std::array<std::string, 3> externalfolders{"externals/picojson", "externals/simplecpp", "externals/tinyxml2"};
|
||||||
|
|
||||||
// Is the dependency already included?
|
// Is the dependency already included?
|
||||||
if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end())
|
if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end())
|
||||||
|
@ -102,10 +103,15 @@ static void getDeps(const std::string &filename, std::vector<std::string> &depfi
|
||||||
pos1 += 10;
|
pos1 += 10;
|
||||||
|
|
||||||
const std::string::size_type pos2 = line.find(rightBracket, pos1);
|
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
|
const std::string::size_type traverse_pos = hfile.find("/../");
|
||||||
hfile.erase(0, 4 + 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);
|
getDeps(hfile, depfiles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +142,7 @@ static std::string getCppFiles(std::vector<std::string> &files, const std::strin
|
||||||
|
|
||||||
// add *.cpp files to the "files" vector..
|
// add *.cpp files to the "files" vector..
|
||||||
for (const std::pair<const std::string&, size_t> file : filemap) {
|
for (const std::pair<const std::string&, size_t> file : filemap) {
|
||||||
if (file.first.find(".cpp") != std::string::npos)
|
if (endsWith(file.first, ".cpp"))
|
||||||
files.push_back(file.first);
|
files.push_back(file.first);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
|
|
Loading…
Reference in New Issue