Use more unordered_maps to improve performance in c++11 builds
authorLoic Blot <loic.blot@unix-experience.fr>
Thu, 6 Oct 2016 06:48:20 +0000 (08:48 +0200)
committersfan5 <sfan5@live.de>
Thu, 6 Oct 2016 10:33:35 +0000 (12:33 +0200)
src/client.cpp
src/client.h
src/clientobject.cpp
src/clientobject.h
src/content_cao.cpp
src/network/clientpackethandler.cpp
src/script/lua_api/l_mapgen.cpp
src/server.cpp
src/util/string.h

index a599e21dca96951b11d0970295cbee5c3c2696f8..63653998a54c9d47276df8e0848c987e5f320107 100644 (file)
@@ -623,10 +623,8 @@ void Client::step(float dtime)
                Update positions of sounds attached to objects
        */
        {
-               for(std::map<int, u16>::iterator
-                               i = m_sounds_to_objects.begin();
-                               i != m_sounds_to_objects.end(); ++i)
-               {
+               for(UNORDERED_MAP<int, u16>::iterator i = m_sounds_to_objects.begin();
+                               i != m_sounds_to_objects.end(); ++i) {
                        int client_id = i->first;
                        u16 object_id = i->second;
                        ClientActiveObject *cao = m_env.getActiveObject(object_id);
@@ -645,8 +643,7 @@ void Client::step(float dtime)
                m_removed_sounds_check_timer = 0;
                // Find removed sounds and clear references to them
                std::vector<s32> removed_server_ids;
-               for(std::map<s32, int>::iterator
-                               i = m_sounds_server_to_client.begin();
+               for(UNORDERED_MAP<s32, int>::iterator i = m_sounds_server_to_client.begin();
                                i != m_sounds_server_to_client.end();) {
                        s32 server_id = i->first;
                        int client_id = i->second;
index fb479068f1a68be163b0a9f386a5d14d35d53477..a71c1dcbcd08a1d7886d20be18a61aff55ab255d 100644 (file)
@@ -663,11 +663,11 @@ private:
        // Sounds
        float m_removed_sounds_check_timer;
        // Mapping from server sound ids to our sound ids
-       std::map<s32, int> m_sounds_server_to_client;
+       UNORDERED_MAP<s32, int> m_sounds_server_to_client;
        // And the other way!
-       std::map<int, s32> m_sounds_client_to_server;
+       UNORDERED_MAP<int, s32> m_sounds_client_to_server;
        // And relations to objects
-       std::map<int, u16> m_sounds_to_objects;
+       UNORDERED_MAP<int, u16> m_sounds_to_objects;
 
        // Privileges
        UNORDERED_SET<std::string> m_privileges;
index a11757ea634829e3b2537a6f9829875247140faf..ff3f4718765a293b1d378c19c4c75b864ab0a1c8 100644 (file)
@@ -43,12 +43,11 @@ ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,
                IGameDef *gamedef, ClientEnvironment *env)
 {
        // Find factory function
-       std::map<u16, Factory>::iterator n;
-       n = m_types.find(type);
+       UNORDERED_MAP<u16, Factory>::iterator n = m_types.find(type);
        if(n == m_types.end()) {
                // If factory is not found, just return.
-               warningstream<<"ClientActiveObject: No factory for type="
-                               <<(int)type<<std::endl;
+               warningstream << "ClientActiveObject: No factory for type="
+                               << (int)type << std::endl;
                return NULL;
        }
 
@@ -59,8 +58,7 @@ ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,
 
 void ClientActiveObject::registerType(u16 type, Factory f)
 {
-       std::map<u16, Factory>::iterator n;
-       n = m_types.find(type);
+       UNORDERED_MAP<u16, Factory>::iterator n = m_types.find(type);
        if(n != m_types.end())
                return;
        m_types[type] = f;
index 3cc7c239156119c79eeaeb91f1d48edbf02632ab..c4e1a634b056b68d7a5f44faafb77995fcc3b821 100644 (file)
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_extrabloated.h"
 #include "activeobject.h"
 #include <map>
+#include "util/cpp11_container.h"
 
 /*
 
@@ -103,7 +104,7 @@ protected:
        ClientEnvironment *m_env;
 private:
        // Used for creating objects based on type
-       static std::map<u16, Factory> m_types;
+       static UNORDERED_MAP<u16, Factory> m_types;
 };
 
 struct DistanceSortedActiveObject
index a141690f6a38df2dbb42f532057dae859cf6db1a..33dae68224ba5e71d1af39386016365cbe2192a9 100644 (file)
@@ -51,7 +51,7 @@ struct ToolCapabilities;
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
-std::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
+UNORDERED_MAP<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
 
 SmoothTranslator::SmoothTranslator():
        vect_old(0,0,0),
index 48c573da594ae77977c7336b732bed57e2527557..6d42edd7d8055f276c0fbee12c06a3f446f2a76a 100644 (file)
@@ -812,9 +812,7 @@ void Client::handleCommand_StopSound(NetworkPacket* pkt)
 
        *pkt >> server_id;
 
-       std::map<s32, int>::iterator i =
-               m_sounds_server_to_client.find(server_id);
-
+       UNORDERED_MAP<s32, int>::iterator i = m_sounds_server_to_client.find(server_id);
        if (i != m_sounds_server_to_client.end()) {
                int client_id = i->second;
                m_sound->stopSound(client_id);
index a176f4f52c026fc4193b1936f71a46fd6ffd5253..da8e71cdc67554a719eb9794a6ed4c039531546d 100644 (file)
@@ -244,7 +244,7 @@ bool read_schematic_def(lua_State *L, int index,
        schem->schemdata = new MapNode[numnodes];
 
        size_t names_base = names->size();
-       std::map<std::string, content_t> name_id_map;
+       UNORDERED_MAP<std::string, content_t> name_id_map;
 
        u32 i = 0;
        for (lua_pushnil(L); lua_next(L, -2); i++, lua_pop(L, 1)) {
@@ -266,7 +266,7 @@ bool read_schematic_def(lua_State *L, int index,
                u8 param2 = getintfield_default(L, -1, "param2", 0);
 
                //// Find or add new nodename-to-ID mapping
-               std::map<std::string, content_t>::iterator it = name_id_map.find(name);
+               UNORDERED_MAP<std::string, content_t>::iterator it = name_id_map.find(name);
                content_t name_index;
                if (it != name_id_map.end()) {
                        name_index = it->second;
index a8494f76e176c1b0b6fb7881efeb851e3d3a3626..e9983ba117f3f606f313d52075196f5d825c04ec 100644 (file)
@@ -794,7 +794,7 @@ void Server::AsyncRunStep(bool initial_step)
 
                // Key = object id
                // Value = data sent by object
-               std::map<u16, std::vector<ActiveObjectMessage>* > buffered_messages;
+               UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* > buffered_messages;
 
                // Get active object messages from environment
                for(;;) {
@@ -803,7 +803,7 @@ void Server::AsyncRunStep(bool initial_step)
                                break;
 
                        std::vector<ActiveObjectMessage>* message_list = NULL;
-                       std::map<u16, std::vector<ActiveObjectMessage>* >::iterator n;
+                       UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator n;
                        n = buffered_messages.find(aom.id);
                        if (n == buffered_messages.end()) {
                                message_list = new std::vector<ActiveObjectMessage>;
@@ -824,7 +824,7 @@ void Server::AsyncRunStep(bool initial_step)
                        std::string reliable_data;
                        std::string unreliable_data;
                        // Go through all objects in message buffer
-                       for (std::map<u16, std::vector<ActiveObjectMessage>* >::iterator
+                       for (UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator
                                        j = buffered_messages.begin();
                                        j != buffered_messages.end(); ++j) {
                                // If object is not known by client, skip it
@@ -868,7 +868,7 @@ void Server::AsyncRunStep(bool initial_step)
                m_clients.unlock();
 
                // Clear buffered_messages
-               for(std::map<u16, std::vector<ActiveObjectMessage>* >::iterator
+               for(UNORDERED_MAP<u16, std::vector<ActiveObjectMessage>* >::iterator
                                i = buffered_messages.begin();
                                i != buffered_messages.end(); ++i) {
                        delete i->second;
index 724543a365f5804a7e3ebeba58384ffd223c5d9c..572c371502c5965167c764d3110cd72488034b2d 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define UTIL_STRING_HEADER
 
 #include "irrlichttypes_bloated.h"
+#include "cpp11_container.h"
 #include <stdlib.h>
 #include <string>
 #include <cstring>
@@ -54,7 +55,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        (((unsigned char)(x) < 0xe0) ? 2 :     \
        (((unsigned char)(x) < 0xf0) ? 3 : 4))
 
-typedef std::map<std::string, std::string> StringMap;
+typedef UNORDERED_MAP<std::string, std::string> StringMap;
 
 struct FlagDesc {
        const char *name;