Codechange: use std::sort() to sort file lists

pull/88/head
glx 5 years ago committed by PeterN
parent b52561fd38
commit 5b77102b63

@ -47,21 +47,20 @@ extern void GetOldSaveGameName(const char *file, char *title, const char *last);
/**
* Compare two FiosItem's. Used with sort when sorting the file list.
* @param da A pointer to the first FiosItem to compare.
* @param db A pointer to the second FiosItem to compare.
* @return -1, 0 or 1, depending on how the two items should be sorted.
* @param other The FiosItem to compare to.
* @return for ascending order: returns true if da < db. Vice versa for descending order.
*/
int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
bool FiosItem::operator< (const FiosItem &other) const
{
int r = 0;
bool r = false;
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) {
r = da->mtime < db->mtime ? -1 : 1;
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && (*this).mtime != other.mtime) {
r = (*this).mtime < other.mtime;
} else {
r = strcasecmp(da->title, db->title);
r = strcasecmp((*this).title, other.title) < 0;
}
if (_savegame_sort_order & SORT_DESCENDING) r = -r;
if (_savegame_sort_order & SORT_DESCENDING) r = !r;
return r;
}
@ -380,7 +379,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
{
SortingBits order = _savegame_sort_order;
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
QSortT(file_list.files.data(), file_list.files.size(), CompareFiosItems);
std::sort(file_list.files.begin(), file_list.files.end());
_savegame_sort_order = order;
}
@ -395,7 +394,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
scanner.Scan(nullptr, subdir, true, true);
}
QSortT(file_list.Get(sort_start), file_list.Length() - sort_start, CompareFiosItems);
std::sort(file_list.files.begin() + sort_start, file_list.files.end());
/* Show drives */
FiosGetDrives(file_list);

@ -107,6 +107,7 @@ struct FiosItem {
uint64 mtime;
char title[64];
char name[MAX_PATH];
bool operator< (const FiosItem &other) const;
};
/** List of file information. */
@ -227,6 +228,4 @@ void FiosMakeSavegameName(char *buf, const char *name, const char *last);
FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const char *file, const char *ext, char *title, const char *last);
int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b);
#endif /* FIOS_H */

@ -260,8 +260,7 @@ static void SortSaveGameList(FileList &file_list)
}
}
size_t s_amount = file_list.Length() - sort_start - sort_end;
QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
std::sort(file_list.files.begin() + sort_start, file_list.files.end() - sort_end);
}
struct SaveLoadWindow : public Window {

Loading…
Cancel
Save