diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-05 20:12:54 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-05 20:12:54 +0100 |
commit | 40c2c18a3fd68b30c29effa79a9f0acd45ff3401 (patch) | |
tree | 29b6f6856b2518f2eec00b584c4b3624bb73b9f2 | |
parent | c00eed90d3e803cd2cc639bd4b97a6427753250c (diff) | |
download | minetest-40c2c18a3fd68b30c29effa79a9f0acd45ff3401.tar.gz minetest-40c2c18a3fd68b30c29effa79a9f0acd45ff3401.tar.bz2 minetest-40c2c18a3fd68b30c29effa79a9f0acd45ff3401.zip |
l_get_modnames: Compare using std::sort instead of a custom function which does same work
-rw-r--r-- | src/script/lua_api/l_server.cpp | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 16331a933..fcdd8c2ff 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -367,34 +367,18 @@ int ModApiServer::l_get_modnames(lua_State *L) NO_MAP_LOCK_REQUIRED; // Get a list of mods - std::vector<std::string> mods_unsorted; - std::list<std::string> mods_sorted; - getServer(L)->getModNames(mods_unsorted); + std::vector<std::string> modlist; + getServer(L)->getModNames(modlist); // Take unsorted items from mods_unsorted and sort them into // mods_sorted; not great performance but the number of mods on a // server will likely be small. - for(std::vector<std::string>::iterator i = mods_unsorted.begin(); - i != mods_unsorted.end(); ++i) { - bool added = false; - for(std::list<std::string>::iterator x = mods_sorted.begin(); - x != mods_sorted.end(); ++x) { - // I doubt anybody using Minetest will be using - // anything not ASCII based :) - if(i->compare(*x) <= 0) { - mods_sorted.insert(x, *i); - added = true; - break; - } - } - if(!added) - mods_sorted.push_back(*i); - } + std::sort(modlist.begin(), modlist.end()); // Package them up for Lua - lua_createtable(L, mods_sorted.size(), 0); - std::list<std::string>::iterator iter = mods_sorted.begin(); - for (u16 i = 0; iter != mods_sorted.end(); iter++) { + lua_createtable(L, modlist.size(), 0); + std::vector<std::string>::iterator iter = modlist.begin(); + for (u16 i = 0; iter != modlist.end(); iter++) { lua_pushstring(L, iter->c_str()); lua_rawseti(L, -2, ++i); } |