Performance improvement: Use std::list instead of std::vector for request_media, Server::getModNames, Environment::m_simple_objects.

* Also remove unused Server::m_modspaths
This commit is contained in:
Loic Blot 2015-03-05 10:43:08 +01:00
parent b214cde5b4
commit 365e4ae0fa
8 changed files with 16 additions and 21 deletions

@ -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);
}

@ -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();

@ -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) {

@ -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){

@ -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;

@ -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();

@ -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);
}
}

@ -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;
/*