diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2018-03-08 20:03:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-08 20:03:43 +0100 |
commit | f35236afea5c23c9aa3a038aac8562c509ad39c2 (patch) | |
tree | c6cd3b57fab325ef880bf623fb1f5e251b47dc93 /src | |
parent | 6cfd699b9f898be6142f5f2bbd459666aa0f0bb8 (diff) | |
download | minetest-f35236afea5c23c9aa3a038aac8562c509ad39c2.tar.gz minetest-f35236afea5c23c9aa3a038aac8562c509ad39c2.tar.bz2 minetest-f35236afea5c23c9aa3a038aac8562c509ad39c2.zip |
mods.cpp/h: little performance improvement in getModsInPath (+ codestyle) (#7108)
* mods.cpp/h: little performance improvement in getModsInPath
Diffstat (limited to 'src')
-rw-r--r-- | src/mods.cpp | 17 | ||||
-rw-r--r-- | src/mods.h | 10 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/mods.cpp b/src/mods.cpp index dae492339..a71644d01 100644 --- a/src/mods.cpp +++ b/src/mods.cpp @@ -85,24 +85,31 @@ void parseModContents(ModSpec &spec) } } -std::map<std::string, ModSpec> getModsInPath(std::string path, bool part_of_modpack) +std::map<std::string, ModSpec> getModsInPath(const std::string &path, + bool part_of_modpack) { // NOTE: this function works in mutual recursion with parseModContents std::map<std::string, ModSpec> result; std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path); + std::string modpath; + for (const fs::DirListNode &dln : dirlist) { - if(!dln.dir) + if (!dln.dir) continue; + const std::string &modname = dln.name; // Ignore all directories beginning with a ".", especially // VCS directories like ".git" or ".svn" if (modname[0] == '.') continue; - std::string modpath = path + DIR_DELIM + modname; - ModSpec spec(modname, modpath); - spec.part_of_modpack = part_of_modpack; + modpath.clear(); + modpath.append(path) + .append(DIR_DELIM) + .append(modname); + + ModSpec spec(modname, modpath, part_of_modpack); parseModContents(spec); result.insert(std::make_pair(modname, spec)); } diff --git a/src/mods.h b/src/mods.h index 50ada328e..c16df30e6 100644 --- a/src/mods.h +++ b/src/mods.h @@ -45,16 +45,22 @@ struct ModSpec bool is_modpack = false; // if modpack: std::map<std::string,ModSpec> modpack_content; - ModSpec(const std::string &name_="", const std::string &path_=""): + ModSpec(const std::string &name_ = "", const std::string &path_ = ""): name(name_), path(path_) {} + ModSpec(const std::string &name_, const std::string &path_, bool part_of_modpack_): + name(name_), + path(path_), + part_of_modpack(part_of_modpack_) + {} }; // Retrieves depends, optdepends, is_modpack and modpack_content void parseModContents(ModSpec &mod); -std::map<std::string,ModSpec> getModsInPath(std::string path, bool part_of_modpack = false); +std::map<std::string,ModSpec> getModsInPath(const std::string &path, + bool part_of_modpack = false); // replaces modpack Modspecs with their content std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods); |