summaryrefslogtreecommitdiff
path: root/build_vehicle_gui.c
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-10-10 15:46:03 +0000
committerbjarni <bjarni@openttd.org>2006-10-10 15:46:03 +0000
commit8d5033ee25d269262c7fea940e59b1bebf1c0d45 (patch)
tree557c5a9d6c1b00e073020983264f5bc8f970ecd6 /build_vehicle_gui.c
parent1928632f954cdd8e73c0336a5338455e675be0b3 (diff)
downloadopenttd-8d5033ee25d269262c7fea940e59b1bebf1c0d45.tar.xz
(svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
Now both names are checked against the cache (instead of just one of them) and we got rid of some global vars
Diffstat (limited to 'build_vehicle_gui.c')
-rw-r--r--build_vehicle_gui.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/build_vehicle_gui.c b/build_vehicle_gui.c
index 14902d49b..6fb3d0828 100644
--- a/build_vehicle_gui.c
+++ b/build_vehicle_gui.c
@@ -88,35 +88,32 @@ static int CDECL EngineIntroDateSorter(const void *a, const void *b)
return _internal_sort_order ? -r : r;
}
-static EngineID _last_engine; // cached vehicle to hopefully speed up name-sorting
-
-static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting
static int CDECL EngineNameSorter(const void *a, const void *b)
{
+ static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
+ static char last_name[2][64] = { "\0", "\0" };
+
const EngineID va = *(const EngineID*)a;
const EngineID vb = *(const EngineID*)b;
- char buf1[64] = "\0";
int r;
- SetDParam(0, GetCustomEngineName(va));
- GetString(buf1, STR_JUST_STRING);
-
- if (vb != _last_engine) {
- _last_engine = vb;
- _bufcache[0] = '\0';
+ if (va != last_engine[0]) {
+ last_engine[0] = va;
+ GetString(last_name[0], GetCustomEngineName(va));
+ }
- SetDParam(0, GetCustomEngineName(vb));
- GetString(_bufcache, STR_JUST_STRING);
+ if (vb != last_engine[1]) {
+ last_engine[1] = vb;
+ GetString(last_name[1], GetCustomEngineName(vb));
}
- r = strcmp(buf1, _bufcache); // sort by name
+ r = strcmp(last_name[0], last_name[1]); // sort by name
if (r == 0) {
/* Use EngineID to sort instead since we want consistent sorting */
return EngineNumberSorter(a, b);
}
-
- return (_internal_sort_order & 1) ? -r : r;
+ return _internal_sort_order ? -r : r;
}
static int CDECL EngineReliabilitySorter(const void *a, const void *b)