From 4d5443affa2cccfbf84afbd3790dcc105e5edef0 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 27 Mar 2011 16:42:47 +0200 Subject: [PATCH] added demo loading speed enhancement by MAP94. Closes #555 --- src/base/tl/array.h | 3 ++- src/base/tl/sorted_array.h | 11 +++++++++++ src/game/client/components/menus_demo.cpp | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/base/tl/array.h b/src/base/tl/array.h index ebc276fc4..6aff3c714 100644 --- a/src/base/tl/array.h +++ b/src/base/tl/array.h @@ -242,7 +242,8 @@ public: */ void set_size(int new_size) { - alloc(new_size); + if(list_size < new_size) + alloc(new_size); num_elements = new_size; } diff --git a/src/base/tl/sorted_array.h b/src/base/tl/sorted_array.h index 7ca7ff8d3..7c45cf286 100644 --- a/src/base/tl/sorted_array.h +++ b/src/base/tl/sorted_array.h @@ -23,6 +23,17 @@ public: return parent::insert(item, partition_binary(all(), item)); } + int add_unsorted(const T& item) + { + return parent::add(item); + } + + void sort_range() + { + sort(all()); + } + + /* Function: all Returns a sorted range that contains the whole array. diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 3d3591781..94b315d7a 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -457,7 +457,7 @@ int CMenus::DemolistFetchCallback(const char *pName, int IsDir, int StorageType, } Item.m_IsDir = IsDir != 0; Item.m_StorageType = StorageType; - pSelf->m_lDemos.add(Item); + pSelf->m_lDemos.add_unsorted(Item); return 0; } @@ -468,6 +468,7 @@ void CMenus::DemolistPopulate() if(!str_comp(m_aCurrentDemoFolder, "demos")) m_DemolistStorageType = IStorage::TYPE_ALL; Storage()->ListDirectory(m_DemolistStorageType, m_aCurrentDemoFolder, DemolistFetchCallback, this); + m_lDemos.sort_range(); } void CMenus::DemolistOnUpdate(bool Reset)