]> git.lizzy.rs Git - minetest.git/commitdiff
Use std::vector instead of std::list in StaticObjectList and MutexedMap::getValues()
authorLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Mar 2015 16:18:57 +0000 (17:18 +0100)
committerLoic Blot <loic.blot@unix-experience.fr>
Wed, 4 Mar 2015 16:22:37 +0000 (17:22 +0100)
src/environment.cpp
src/itemdef.cpp
src/staticobject.cpp
src/staticobject.h
src/util/container.h

index 0a3d360199d2c9d99a8a01a972afee200ca6f425..9daa9e042b41d6ab0dcb167de287ac42a9b95a28 100644 (file)
@@ -1675,12 +1675,13 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
        // Ignore if no stored objects (to not set changed flag)
        if(block->m_static_objects.m_stored.empty())
                return;
+
        verbosestream<<"ServerEnvironment::activateObjects(): "
                        <<"activating objects of block "<<PP(block->getPos())
                        <<" ("<<block->m_static_objects.m_stored.size()
                        <<" objects)"<<std::endl;
        bool large_amount = (block->m_static_objects.m_stored.size() > g_settings->getU16("max_objects_per_block"));
-       if(large_amount){
+       if (large_amount) {
                errorstream<<"suspiciously large amount of objects detected: "
                                <<block->m_static_objects.m_stored.size()<<" in "
                                <<PP(block->getPos())
@@ -1695,7 +1696,7 @@ void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s)
 
        // Activate stored objects
        std::vector<StaticObject> new_stored;
-       for(std::list<StaticObject>::iterator
+       for (std::vector<StaticObject>::iterator
                        i = block->m_static_objects.m_stored.begin();
                        i != block->m_static_objects.m_stored.end(); ++i) {
                StaticObject &s_obj = *i;
index d356b96c5379d4b2f68cb7becf2416853c40e060..3b4d2596ab0467be3e6b2dc0d4249b2c9435c30b 100644 (file)
@@ -249,8 +249,8 @@ class CItemDefManager: public IWritableItemDefManager
        virtual ~CItemDefManager()
        {
 #ifndef SERVER
-               const std::list<ClientCached*> &values = m_clientcached.getValues();
-               for(std::list<ClientCached*>::const_iterator
+               const std::vector<ClientCached*> &values = m_clientcached.getValues();
+               for(std::vector<ClientCached*>::const_iterator
                                i = values.begin(); i != values.end(); ++i)
                {
                        ClientCached *cc = *i;
index 16d98605b6b75c775abac30c9595edcbb803a98a..2e7d45a47fef74a0877babd2d5a48169c52d37ee 100644 (file)
@@ -47,10 +47,9 @@ void StaticObjectList::serialize(std::ostream &os)
        // count
        u16 count = m_stored.size() + m_active.size();
        writeU16(os, count);
-       for(std::list<StaticObject>::iterator
+       for(std::vector<StaticObject>::iterator
                        i = m_stored.begin();
-                       i != m_stored.end(); ++i)
-       {
+                       i != m_stored.end(); ++i) {
                StaticObject &s_obj = *i;
                s_obj.serialize(os);
        }
@@ -68,8 +67,7 @@ void StaticObjectList::deSerialize(std::istream &is)
        u8 version = readU8(is);
        // count
        u16 count = readU16(is);
-       for(u16 i=0; i<count; i++)
-       {
+       for(u16 i = 0; i < count; i++) {
                StaticObject s_obj;
                s_obj.deSerialize(is, version);
                m_stored.push_back(s_obj);
index 575c15b18d9de747c9fbaf717cb30ce169d90a22..4918a14663eb127c5227bb824e911332755aad64 100644 (file)
@@ -23,7 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_bloated.h"
 #include <string>
 #include <sstream>
-#include <list>
+#include <vector>
 #include <map>
 #include "debug.h"
 
@@ -95,7 +95,7 @@ class StaticObjectList
                from m_stored and inserted to m_active.
                The caller directly manipulates these containers.
        */
-       std::list<StaticObject> m_stored;
+       std::vector<StaticObject> m_stored;
        std::map<u16, StaticObject> m_active;
 
 private:
index 5e9f13d886bb146e0fbd623fadff5a5bfa9e7b56..3ffd885e49e1b63e9089567dac5af5e412d670f9 100644 (file)
@@ -77,7 +77,6 @@ class UniqueQueue
        std::queue<Value> m_queue;
 };
 
-#if 1
 template<typename Key, typename Value>
 class MutexedMap
 {
@@ -109,9 +108,9 @@ class MutexedMap
                return true;
        }
 
-       std::list<Value> getValues()
+       std::vector<Value> getValues()
        {
-               std::list<Value> result;
+               std::vector<Value> result;
                for(typename std::map<Key, Value>::iterator
                        i = m_values.begin();
                        i != m_values.end(); ++i){
@@ -129,7 +128,6 @@ class MutexedMap
        std::map<Key, Value> m_values;
        JMutex m_mutex;
 };
-#endif
 
 /*
 Generates ids for comparable values.