UI: Quit sorting when done.

This will prevent keeping the gameInfo objects alive unnecessarily.
This commit is contained in:
Unknown W. Brackets 2018-06-04 21:02:40 -07:00 committed by Henrik Rydgård
parent 4fb606839c
commit f0be2d5f88
2 changed files with 15 additions and 3 deletions

View file

@ -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<bool(const View *, const View *)> CompareFunc;
typedef std::function<bool()> 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<SortedLinearLayout *>(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;

View file

@ -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);