From 365e4ae0faee79ff7b62396f27667e8315ba94d4 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 5 Mar 2015 10:43:08 +0100 Subject: [PATCH] Performance improvement: Use std::list instead of std::vector for request_media, Server::getModNames, Environment::m_simple_objects. * Also remove unused Server::m_modspaths --- src/client.cpp | 4 ++-- src/client.h | 2 +- src/clientmedia.cpp | 2 +- src/environment.cpp | 12 +++++------- src/environment.h | 2 +- src/script/lua_api/l_server.cpp | 5 +++-- src/server.cpp | 5 ++--- 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 &file_requests) +void Client::request_media(const std::vector &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 &file_requests) *pkt << (u16) (file_requests_size & 0xFFFF); - for(std::list::const_iterator i = file_requests.begin(); + for(std::vector::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 &file_requests); + void request_media(const std::vector &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 file_requests; + std::vector file_requests; for (std::map::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::iterator - i = m_simple_objects.begin(); i != m_simple_objects.end(); ++i) - { + for(std::vector::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::iterator - i = m_simple_objects.begin(); i != m_simple_objects.end();) - { + for(std::vector::iterator + i = m_simple_objects.begin(); i != m_simple_objects.end();) { ClientSimpleObject *simple = *i; - std::list::iterator cur = i; + std::vector::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 m_active_objects; - std::list m_simple_objects; + std::vector m_simple_objects; std::list 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 mods_unsorted, mods_sorted; + std::vector mods_unsorted; + std::list 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::iterator i = mods_unsorted.begin(); + for(std::vector::iterator i = mods_unsorted.begin(); i != mods_unsorted.end(); ++i) { bool added = false; for(std::list::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 &modlist) +void Server::getModNames(std::vector &modlist) { - for(std::vector::iterator i = m_mods.begin(); i != m_mods.end(); i++) - { + for(std::vector::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 &modlist); + void getModNames(std::vector &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 m_modspaths; - bool m_shutdown_requested; /* -- 2.25.1