summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-04-13 23:11:56 +0200
committerglx22 <glx22@users.noreply.github.com>2019-04-18 21:49:34 +0200
commit9388fa2aa12db72b80d10def4752d5c37bb806cb (patch)
tree5f6cf5d7dfa146ff7aa91afbb0ef9ccd89e8083f /src
parent889927261452da616c5289f016e84b6f201141e8 (diff)
downloadopenttd-9388fa2aa12db72b80d10def4752d5c37bb806cb.tar.xz
Codechange: use std::vector to sort _all_grfs linked list
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_config.cpp21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 2eef5d183..676f677bc 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -709,16 +709,13 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const
/**
* Simple sorter for GRFS
- * @param p1 the first GRFConfig *
- * @param p2 the second GRFConfig *
- * @return the same strcmp would return for the name of the NewGRF.
+ * @param c1 the first GRFConfig *
+ * @param c2 the second GRFConfig *
+ * @return true if the name of first NewGRF is before the name of the second.
*/
-static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2)
+static bool GRFSorter(GRFConfig * const &c1, GRFConfig * const &c2)
{
- const GRFConfig *c1 = *p1;
- const GRFConfig *c2 = *p2;
-
- return strnatcmp(c1->GetName(), c2->GetName());
+ return strnatcmp(c1->GetName(), c2->GetName()) < 0;
}
/**
@@ -740,16 +737,16 @@ void DoScanNewGRFFiles(NewGRFScanCallback *callback)
/* Sort the linked list using quicksort.
* For that we first have to make an array, then sort and
* then remake the linked list. */
- GRFConfig **to_sort = MallocT<GRFConfig*>(num);
+ std::vector<GRFConfig *> to_sort;
uint i = 0;
for (GRFConfig *p = _all_grfs; p != nullptr; p = p->next, i++) {
- to_sort[i] = p;
+ to_sort.push_back(p);
}
/* Number of files is not necessarily right */
num = i;
- QSortT(to_sort, num, &GRFSorter);
+ std::sort(to_sort.begin(), to_sort.end(), GRFSorter);
for (i = 1; i < num; i++) {
to_sort[i - 1]->next = to_sort[i];
@@ -757,8 +754,6 @@ void DoScanNewGRFFiles(NewGRFScanCallback *callback)
to_sort[num - 1]->next = nullptr;
_all_grfs = to_sort[0];
- free(to_sort);
-
NetworkAfterNewGRFScan();
}