Skip to content

Commit

Permalink
UI: Quit sorting when done.
Browse files Browse the repository at this point in the history
This will prevent keeping the gameInfo objects alive unnecessarily.
  • Loading branch information
unknownbrackets authored and hrydgard committed Jun 6, 2018
1 parent 4fb6068 commit f0be2d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 14 additions & 3 deletions UI/SavedataScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -125,25 +126,30 @@ class SavedataPopupScreen : public PopupScreen {
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;
}

void Update() override;

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();
}

Expand Down Expand Up @@ -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);
}
}
}
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions UI/SavedataScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SavedataBrowser : public UI::LinearLayout {
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);
Expand Down

0 comments on commit f0be2d5

Please sign in to comment.