]> git.tdb.fi Git - libs/gl.git/commitdiff
Prefer more compact containers
authorMikko Rasa <tdb@tdb.fi>
Fri, 17 Sep 2021 23:09:33 +0000 (02:09 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 17 Sep 2021 23:09:33 +0000 (02:09 +0300)
source/render/orderedscene.cpp
source/render/orderedscene.h
source/resources/resourcemanager.cpp
source/resources/resourcemanager.h

index 5912e747df787295bfbf91f83bf86756408f10db..bf1a62481310d4b5fe9e556ee24cdb27b9d8b25a 100644 (file)
@@ -18,7 +18,7 @@ void OrderedScene::remove(Renderable &r)
 
 void OrderedScene::prepend(Renderable &r)
 {
-       renderables.push_front(&r);
+       renderables.insert(renderables.begin(), &r);
 }
 
 void OrderedScene::insert(unsigned index, Renderable &r)
index aa43eb73ea83e4dd90595550ab6d7683ffb6e113..3e2974e9d25a32ed10992c23d2f2eaa349b37a94 100644 (file)
@@ -17,7 +17,7 @@ public:
        using Scene::Loader;
 
 private:
-       std::list<Renderable *> renderables;
+       std::vector<Renderable *> renderables;
 
 public:
        virtual void add(Renderable &);
index 4bac0aec841aa1552f3062a42a93f57ea2b7fb31..91acb3d0baf623e89fea7777cd022006ec847401 100644 (file)
@@ -214,7 +214,7 @@ void ResourceManager::tick()
 
 void ResourceManager::dispatch_work()
 {
-       queue.sort(age_order);
+       sort(queue, age_order);
 
        if(queue.front()->last_used+min_retain_frames<frame)
        {
@@ -406,7 +406,8 @@ void ResourceManager::LoadingThread::main()
                        }
 
                        MutexLock lock(queue_mutex);
-                       sync_queue.splice(sync_queue.end(), async_queue, async_queue.begin());
+                       sync_queue.push_back(async_queue.front());
+                       async_queue.pop_front();
                        wait_for_work = async_queue.empty();
                }
                else
@@ -414,7 +415,7 @@ void ResourceManager::LoadingThread::main()
        }
 }
 
-ResourceManager::ManagedResource *ResourceManager::LoadingThread::front(list<ManagedResource *> &que)
+ResourceManager::ManagedResource *ResourceManager::LoadingThread::front(deque<ManagedResource *> &que)
 {
        MutexLock lock(queue_mutex);
        if(que.empty())
@@ -519,7 +520,8 @@ bool ResourceManager::LoadingThread::sync()
                {
                        MutexLock lock(queue_mutex);
                        bool was_empty = async_queue.empty();
-                       async_queue.splice(async_queue.end(), sync_queue, sync_queue.begin());
+                       async_queue.push_back(sync_queue.front());
+                       sync_queue.pop_front();
                        if(was_empty)
                                sem.signal();
                }
index 2596999750724f32c239da69c4f261bc6ae324a3..38437a727fd9a7d94cc24b048123bb62f0a0e35d 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GL_RESOURCEMANAGER_H_
 #define MSP_GL_RESOURCEMANAGER_H_
 
+#include <deque>
 #include <msp/core/inttypes.h>
 #include <msp/core/mutex.h>
 #include <msp/core/semaphore.h>
@@ -81,8 +82,8 @@ private:
        private:
                Semaphore sem;
                Mutex queue_mutex;
-               std::list<ManagedResource *> async_queue;
-               std::list<ManagedResource *> sync_queue;
+               std::deque<ManagedResource *> async_queue;
+               std::deque<ManagedResource *> sync_queue;
                unsigned capacity;
                unsigned size;
                std::list<resource_load_error> error_queue;
@@ -96,7 +97,7 @@ private:
        private:
                virtual void main();
 
-               ManagedResource *front(std::list<ManagedResource *> &);
+               ManagedResource *front(std::deque<ManagedResource *> &);
 
        public:
                void add_resource(ManagedResource &);
@@ -115,7 +116,7 @@ private:
        bool async_loads;
        mutable Mutex map_mutex;
        std::map<const Resource *, ManagedResource> resources;
-       std::list<ManagedResource *> queue;
+       std::deque<ManagedResource *> queue;
        UInt64 total_data_size;
        UInt64 size_limit;
        unsigned frame;