From 5b311d10d50aa1fe0eb4ed4b8e41f0c58e9e7cbf Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 18 Sep 2021 02:09:33 +0300 Subject: [PATCH] Prefer more compact containers --- source/render/orderedscene.cpp | 2 +- source/render/orderedscene.h | 2 +- source/resources/resourcemanager.cpp | 10 ++++++---- source/resources/resourcemanager.h | 9 +++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/source/render/orderedscene.cpp b/source/render/orderedscene.cpp index 5912e747..bf1a6248 100644 --- a/source/render/orderedscene.cpp +++ b/source/render/orderedscene.cpp @@ -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) diff --git a/source/render/orderedscene.h b/source/render/orderedscene.h index aa43eb73..3e2974e9 100644 --- a/source/render/orderedscene.h +++ b/source/render/orderedscene.h @@ -17,7 +17,7 @@ public: using Scene::Loader; private: - std::list renderables; + std::vector renderables; public: virtual void add(Renderable &); diff --git a/source/resources/resourcemanager.cpp b/source/resources/resourcemanager.cpp index 4bac0aec..91acb3d0 100644 --- a/source/resources/resourcemanager.cpp +++ b/source/resources/resourcemanager.cpp @@ -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 &que) +ResourceManager::ManagedResource *ResourceManager::LoadingThread::front(deque &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(); } diff --git a/source/resources/resourcemanager.h b/source/resources/resourcemanager.h index 25969997..38437a72 100644 --- a/source/resources/resourcemanager.h +++ b/source/resources/resourcemanager.h @@ -1,6 +1,7 @@ #ifndef MSP_GL_RESOURCEMANAGER_H_ #define MSP_GL_RESOURCEMANAGER_H_ +#include #include #include #include @@ -81,8 +82,8 @@ private: private: Semaphore sem; Mutex queue_mutex; - std::list async_queue; - std::list sync_queue; + std::deque async_queue; + std::deque sync_queue; unsigned capacity; unsigned size; std::list error_queue; @@ -96,7 +97,7 @@ private: private: virtual void main(); - ManagedResource *front(std::list &); + ManagedResource *front(std::deque &); public: void add_resource(ManagedResource &); @@ -115,7 +116,7 @@ private: bool async_loads; mutable Mutex map_mutex; std::map resources; - std::list queue; + std::deque queue; UInt64 total_data_size; UInt64 size_limit; unsigned frame; -- 2.45.2