mirror of
https://github.com/minetest/minetest.git
synced 2025-01-11 10:30:20 +01:00
mods.cpp/h: little performance improvement in getModsInPath (+ codestyle) (#7108)
* mods.cpp/h: little performance improvement in getModsInPath
This commit is contained in:
parent
6cfd699b9f
commit
f35236afea
15
src/mods.cpp
15
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
|
// NOTE: this function works in mutual recursion with parseModContents
|
||||||
|
|
||||||
std::map<std::string, ModSpec> result;
|
std::map<std::string, ModSpec> result;
|
||||||
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path);
|
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path);
|
||||||
|
std::string modpath;
|
||||||
|
|
||||||
for (const fs::DirListNode &dln : dirlist) {
|
for (const fs::DirListNode &dln : dirlist) {
|
||||||
if (!dln.dir)
|
if (!dln.dir)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string &modname = dln.name;
|
const std::string &modname = dln.name;
|
||||||
// Ignore all directories beginning with a ".", especially
|
// Ignore all directories beginning with a ".", especially
|
||||||
// VCS directories like ".git" or ".svn"
|
// VCS directories like ".git" or ".svn"
|
||||||
if (modname[0] == '.')
|
if (modname[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
std::string modpath = path + DIR_DELIM + modname;
|
|
||||||
|
|
||||||
ModSpec spec(modname, modpath);
|
modpath.clear();
|
||||||
spec.part_of_modpack = part_of_modpack;
|
modpath.append(path)
|
||||||
|
.append(DIR_DELIM)
|
||||||
|
.append(modname);
|
||||||
|
|
||||||
|
ModSpec spec(modname, modpath, part_of_modpack);
|
||||||
parseModContents(spec);
|
parseModContents(spec);
|
||||||
result.insert(std::make_pair(modname, spec));
|
result.insert(std::make_pair(modname, spec));
|
||||||
}
|
}
|
||||||
|
@ -49,12 +49,18 @@ struct ModSpec
|
|||||||
name(name_),
|
name(name_),
|
||||||
path(path_)
|
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
|
// Retrieves depends, optdepends, is_modpack and modpack_content
|
||||||
void parseModContents(ModSpec &mod);
|
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
|
// replaces modpack Modspecs with their content
|
||||||
std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods);
|
std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods);
|
||||||
|
Loading…
Reference in New Issue
Block a user