diff options
author | rubidium <rubidium@openttd.org> | 2009-09-13 17:39:33 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-09-13 17:39:33 +0000 |
commit | ca7f6f5d7a74b2b517bdbb02125850136e777645 (patch) | |
tree | ba526c2174d091fd2e687cc02e61fe7f5bb368dc | |
parent | 67448246d32d448dab43fe4994a8e788cb727c45 (diff) | |
download | openttd-ca7f6f5d7a74b2b517bdbb02125850136e777645.tar.xz |
(svn r17528) -Codechange: use QSortT instead of qsort for sorting FiosItems
-rw-r--r-- | src/fios.cpp | 15 | ||||
-rw-r--r-- | src/fios.h | 2 | ||||
-rw-r--r-- | src/misc_gui.cpp | 5 |
3 files changed, 10 insertions, 12 deletions
diff --git a/src/fios.cpp b/src/fios.cpp index c9f673493..6310f4553 100644 --- a/src/fios.cpp +++ b/src/fios.cpp @@ -13,6 +13,7 @@ #include "stdafx.h" #include "openttd.h" +#include "core/sort_func.hpp" #include "fios.h" #include "fileio_func.h" #include "tar_type.h" @@ -43,15 +44,13 @@ extern bool FiosGetDiskFreeSpace(const char *path, uint64 *tot); extern void GetOldSaveGameName(const char *file, char *title, const char *last); /** - * Compare two FiosItem's. Used with qsort when sorting the file list. - * @param a A pointer to the first FiosItem to compare. - * @param b A pointer to the second FiosItem to compare. + * 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. */ -int CDECL compare_FiosItems(const void *a, const void *b) +int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db) { - const FiosItem *da = (const FiosItem *)a; - const FiosItem *db = (const FiosItem *)b; int r = 0; if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) { @@ -309,7 +308,7 @@ static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc { byte order = _savegame_sort_order; _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING; - qsort(_fios_items.Begin(), _fios_items.Length(), sizeof(FiosItem), compare_FiosItems); + QSortT(_fios_items.Begin(), _fios_items.Length(), CompareFiosItems); _savegame_sort_order = order; } @@ -324,7 +323,7 @@ static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc scanner.Scan(NULL, subdir, true, true); } - qsort(_fios_items.Get(sort_start), _fios_items.Length() - sort_start, sizeof(FiosItem), compare_FiosItems); + QSortT(_fios_items.Get(sort_start), _fios_items.Length() - sort_start, CompareFiosItems); /* Show drives */ if (mode != SLD_NEW_GAME) FiosGetDrives(); diff --git a/src/fios.h b/src/fios.h index 5b08373e6..06a4856ae 100644 --- a/src/fios.h +++ b/src/fios.h @@ -115,6 +115,6 @@ void FiosMakeSavegameName(char *buf, const char *name, size_t size); /* Determines type of savegame (or tells it is not a savegame) */ FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last); -int CDECL compare_FiosItems(const void *a, const void *b); +int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b); #endif /* FIOS_H */ diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 7e4d019e3..7a4c7f015 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -40,6 +40,7 @@ #include "newgrf_cargo.h" #include "tilehighlight_func.h" #include "querystring_gui.h" +#include "core/sort_func.hpp" #include "table/strings.h" @@ -1746,9 +1747,7 @@ static void MakeSortedSaveGameList() } uint s_amount = _fios_items.Length() - sort_start - sort_end; - if (s_amount > 0) { - qsort(_fios_items.Get(sort_start), s_amount, sizeof(FiosItem), compare_FiosItems); - } + QSortT(_fios_items.Get(sort_start), s_amount, CompareFiosItems); } extern void StartupEngines(); |