From f35236afea5c23c9aa3a038aac8562c509ad39c2 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Thu, 8 Mar 2018 20:03:43 +0100 Subject: mods.cpp/h: little performance improvement in getModsInPath (+ codestyle) (#7108) * mods.cpp/h: little performance improvement in getModsInPath --- src/mods.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/mods.cpp') 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 getModsInPath(std::string path, bool part_of_modpack) +std::map getModsInPath(const std::string &path, + bool part_of_modpack) { // NOTE: this function works in mutual recursion with parseModContents std::map result; std::vector 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)); } -- cgit v1.2.3