From f0be2d5f88470b3806c2f5d9707a3038bb6599c7 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Mon, 4 Jun 2018 21:02:40 -0700 Subject: [PATCH] UI: Quit sorting when done. This will prevent keeping the gameInfo objects alive unnecessarily. --- UI/SavedataScreen.cpp | 17 ++++++++++++++--- UI/SavedataScreen.h | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/UI/SavedataScreen.cpp b/UI/SavedataScreen.cpp index ab39cc4b6f..37f767a82d 100644 --- a/UI/SavedataScreen.cpp +++ b/UI/SavedataScreen.cpp @@ -23,6 +23,7 @@ #include "gfx_es2/draw_buffer.h" #include "i18n/i18n.h" #include "math/curves.h" +#include "thread/prioritizedworkqueue.h" #include "util/text/utf8.h" #include "ui/ui_context.h" #include "ui/view.h" @@ -125,12 +126,13 @@ private: class SortedLinearLayout : public UI::LinearLayout { public: typedef std::function CompareFunc; + typedef std::function DoneFunc; SortedLinearLayout(UI::Orientation orientation, UI::LayoutParams *layoutParams = nullptr) : UI::LinearLayout(orientation, layoutParams) { } - void SetCompare(CompareFunc lessFunc) { + void SetCompare(CompareFunc lessFunc, DoneFunc) { lessFunc_ = lessFunc; } @@ -138,12 +140,16 @@ public: private: CompareFunc lessFunc_; + DoneFunc doneFunc_; }; void SortedLinearLayout::Update() { if (lessFunc_) { std::stable_sort(views_.begin(), views_.end(), lessFunc_); } + if (doneFunc_ && doneFunc_()) { + lessFunc_ = CompareFunc(); + } UI::LinearLayout::Update(); } @@ -314,9 +320,9 @@ void SavedataBrowser::SetSortOption(SavedataSortOption opt) { if (gameList_) { SortedLinearLayout *gl = static_cast(gameList_); if (sortOption_ == SavedataSortOption::FILENAME) { - gl->SetCompare(&ByFilename); + gl->SetCompare(&ByFilename, &SortDone); } else if (sortOption_ == SavedataSortOption::SIZE) { - gl->SetCompare(&BySize); + gl->SetCompare(&BySize, &SortDone); } } } @@ -339,6 +345,11 @@ bool SavedataBrowser::BySize(const UI::View *v1, const UI::View *v2) { return g1info->gameSize > g2info->gameSize; } +bool SavedataBrowser::SortDone() { + PrioritizedWorkQueue *wq = g_gameInfoCache->WorkQueue(); + return wq->Done(); +} + void SavedataBrowser::Refresh() { using namespace UI; diff --git a/UI/SavedataScreen.h b/UI/SavedataScreen.h index d35b4f8920..0ab3e6ed56 100644 --- a/UI/SavedataScreen.h +++ b/UI/SavedataScreen.h @@ -42,6 +42,7 @@ public: private: static bool ByFilename(const UI::View *, const UI::View *); static bool BySize(const UI::View *, const UI::View *); + static bool SortDone(); void Refresh(); UI::EventReturn SavedataButtonClick(UI::EventParams &e);