diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-05 10:43:08 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-03-05 10:44:48 +0100 |
commit | 365e4ae0faee79ff7b62396f27667e8315ba94d4 (patch) | |
tree | 80b4ef80a339433562e23cd47980f4aae87bf938 | |
parent | b214cde5b4a833e1826ec6850b95bf1938c8b0a0 (diff) | |
download | minetest-365e4ae0faee79ff7b62396f27667e8315ba94d4.tar.gz minetest-365e4ae0faee79ff7b62396f27667e8315ba94d4.tar.bz2 minetest-365e4ae0faee79ff7b62396f27667e8315ba94d4.zip |
Performance improvement: Use std::list instead of std::vector for request_media, Server::getModNames, Environment::m_simple_objects.
* Also remove unused Server::m_modspaths
-rw-r--r-- | src/client.cpp | 4 | ||||
-rw-r--r-- | src/client.h | 2 | ||||
-rw-r--r-- | src/clientmedia.cpp | 2 | ||||
-rw-r--r-- | src/environment.cpp | 12 | ||||
-rw-r--r-- | src/environment.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_server.cpp | 5 | ||||
-rw-r--r-- | src/server.cpp | 5 | ||||
-rw-r--r-- | src/server.h | 5 |
8 files changed, 16 insertions, 21 deletions
diff --git a/src/client.cpp b/src/client.cpp index d476f920d..a1ae1e6ab 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -778,7 +778,7 @@ void Client::deletingPeer(con::Peer *peer, bool timeout) string name } */ -void Client::request_media(const std::list<std::string> &file_requests) +void Client::request_media(const std::vector<std::string> &file_requests) { std::ostringstream os(std::ios_base::binary); writeU16(os, TOSERVER_REQUEST_MEDIA); @@ -790,7 +790,7 @@ void Client::request_media(const std::list<std::string> &file_requests) *pkt << (u16) (file_requests_size & 0xFFFF); - for(std::list<std::string>::const_iterator i = file_requests.begin(); + for(std::vector<std::string>::const_iterator i = file_requests.begin(); i != file_requests.end(); ++i) { *pkt << (*i); } diff --git a/src/client.h b/src/client.h index afa519d16..c0146911d 100644 --- a/src/client.h +++ b/src/client.h @@ -516,7 +516,7 @@ public: // Insert a media file appropriately into the appropriate manager bool loadMedia(const std::string &data, const std::string &filename); // Send a request for conventional media transfer - void request_media(const std::list<std::string> &file_requests); + void request_media(const std::vector<std::string> &file_requests); // Send a notification that no conventional media transfer is needed void received_media(); diff --git a/src/clientmedia.cpp b/src/clientmedia.cpp index 7eb505314..1d825c143 100644 --- a/src/clientmedia.cpp +++ b/src/clientmedia.cpp @@ -488,7 +488,7 @@ void ClientMediaDownloader::startConventionalTransfers(Client *client) if (m_uncached_received_count != m_uncached_count) { // Some media files have not been received yet, use the // conventional slow method (minetest protocol) to get them - std::list<std::string> file_requests; + std::vector<std::string> file_requests; for (std::map<std::string, FileStatus*>::iterator it = m_files.begin(); it != m_files.end(); ++it) { diff --git a/src/environment.cpp b/src/environment.cpp index 6cabc0dbc..b1372431f 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2025,9 +2025,8 @@ ClientEnvironment::~ClientEnvironment() delete i->second; } - for(std::list<ClientSimpleObject*>::iterator - i = m_simple_objects.begin(); i != m_simple_objects.end(); ++i) - { + for(std::vector<ClientSimpleObject*>::iterator + i = m_simple_objects.begin(); i != m_simple_objects.end(); ++i) { delete *i; } @@ -2382,11 +2381,10 @@ void ClientEnvironment::step(float dtime) Step and handle simple objects */ g_profiler->avg("CEnv: num of simple objects", m_simple_objects.size()); - for(std::list<ClientSimpleObject*>::iterator - i = m_simple_objects.begin(); i != m_simple_objects.end();) - { + for(std::vector<ClientSimpleObject*>::iterator + i = m_simple_objects.begin(); i != m_simple_objects.end();) { ClientSimpleObject *simple = *i; - std::list<ClientSimpleObject*>::iterator cur = i; + std::vector<ClientSimpleObject*>::iterator cur = i; ++i; simple->step(dtime); if(simple->m_to_be_removed){ diff --git a/src/environment.h b/src/environment.h index 386289307..c9c374413 100644 --- a/src/environment.h +++ b/src/environment.h @@ -521,7 +521,7 @@ private: IGameDef *m_gamedef; IrrlichtDevice *m_irr; std::map<u16, ClientActiveObject*> m_active_objects; - std::list<ClientSimpleObject*> m_simple_objects; + std::vector<ClientSimpleObject*> m_simple_objects; std::list<ClientEnvEvent> m_client_event_queue; IntervalLimiter m_active_object_light_update_interval; IntervalLimiter m_lava_hurt_interval; diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 8d7f6512e..16331a933 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -367,13 +367,14 @@ int ModApiServer::l_get_modnames(lua_State *L) NO_MAP_LOCK_REQUIRED; // Get a list of mods - std::list<std::string> mods_unsorted, mods_sorted; + std::vector<std::string> mods_unsorted; + std::list<std::string> mods_sorted; getServer(L)->getModNames(mods_unsorted); // 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::list<std::string>::iterator i = mods_unsorted.begin(); + 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(); diff --git a/src/server.cpp b/src/server.cpp index 444fbc751..92dbc0370 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3188,10 +3188,9 @@ const ModSpec* Server::getModSpec(const std::string &modname) } return NULL; } -void Server::getModNames(std::list<std::string> &modlist) +void Server::getModNames(std::vector<std::string> &modlist) { - for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++) - { + for(std::vector<ModSpec>::iterator i = m_mods.begin(); i != m_mods.end(); i++) { modlist.push_back(i->name); } } diff --git a/src/server.h b/src/server.h index ee9199da7..50a8861fa 100644 --- a/src/server.h +++ b/src/server.h @@ -327,7 +327,7 @@ public: IWritableCraftDefManager* getWritableCraftDefManager(); const ModSpec* getModSpec(const std::string &modname); - void getModNames(std::list<std::string> &modlist); + void getModNames(std::vector<std::string> &modlist); std::string getBuiltinLuaPath(); inline std::string getWorldPath() { return m_path_world; } @@ -588,9 +588,6 @@ private: Random stuff */ - // Mod parent directory paths - std::list<std::string> m_modspaths; - bool m_shutdown_requested; /* |