Mercurial > hg > openttd
changeset 4804:131ec5d3140c draft
(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
author | bjarni <bjarni@openttd.org> |
---|---|
date | Tue, 10 Oct 2006 15:46:03 +0000 |
parents | 4becc83be4f5 |
children | e7d602200399 |
files | build_vehicle_gui.c |
diffstat | 1 files changed, 13 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/build_vehicle_gui.c +++ b/build_vehicle_gui.c @@ -88,35 +88,32 @@ 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'; - - SetDParam(0, GetCustomEngineName(vb)); - GetString(_bufcache, STR_JUST_STRING); + if (va != last_engine[0]) { + last_engine[0] = va; + GetString(last_name[0], GetCustomEngineName(va)); } - r = strcmp(buf1, _bufcache); // sort by name + if (vb != last_engine[1]) { + last_engine[1] = vb; + GetString(last_name[1], GetCustomEngineName(vb)); + } + + 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)