summaryrefslogtreecommitdiff
path: root/vehicle_gui.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-10-16 10:29:29 +0000
committerpeter1138 <peter1138@openttd.org>2006-10-16 10:29:29 +0000
commitced2372e8d1182e613162db465239b65082fe76d (patch)
tree6c14c36dc469d9ed9f287ba585d7fb925020e836 /vehicle_gui.c
parentaa42711a5949f2010561ce1605cbc9a247a015ed (diff)
downloadopenttd-ced2372e8d1182e613162db465239b65082fe76d.tar.xz
(svn r6789) - Codechange: Tidy up VehicleNameSorter() to use no global vars, and match the style of EngineNameSorter(). This also removes a bug where _internal_name_sorter_id was never set properly for anything other than trains.
Diffstat (limited to 'vehicle_gui.c')
-rw-r--r--vehicle_gui.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c
index 893182fe2..41bb10a67 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -47,8 +47,6 @@ typedef struct vehiclelist_d {
} vehiclelist_d;
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(vehiclelist_d));
-static uint32 _internal_name_sorter_id; // internal StringID for default vehicle-names
-static const Vehicle* _last_vehicle; // cached vehicle to hopefully speed up name-sorting
static bool _internal_sort_order; // descending/ascending
static RailType _railtype_selected_in_replace_gui;
@@ -149,8 +147,6 @@ static void SortVehicleList(vehiclelist_d *vl)
if (!(vl->l.flags & VL_RESORT)) return;
_internal_sort_order = vl->l.flags & VL_DESC;
- _internal_name_sorter_id = STR_SV_TRAIN_NAME;
- _last_vehicle = NULL; // used for "cache" in namesorting
qsort((void*)vl->sort_list, vl->l.list_length, sizeof(vl->sort_list[0]),
_vehicle_sorter[vl->l.sort_type]);
@@ -508,25 +504,34 @@ static int CDECL VehicleNumberSorter(const void *a, const void *b)
return (_internal_sort_order & 1) ? -r : r;
}
-static char _bufcache[64]; // used together with _last_vehicle to hopefully speed up stringsorting
static int CDECL VehicleNameSorter(const void *a, const void *b)
{
+ static const Vehicle *last_vehicle[2] = { NULL, NULL };
+ static char last_name[2][64] = { "", "" };
+
const Vehicle* va = *(const Vehicle**)a;
const Vehicle* vb = *(const Vehicle**)b;
- char buf1[64] = "\0";
int r;
- if (va->string_id != _internal_name_sorter_id) GetString(buf1, va->string_id);
+ if (va != last_vehicle[0]) {
+ last_vehicle[0] = va;
+ if (IsCustomName(va->string_id)) {
+ GetString(last_name[0], va->string_id);
+ } else {
+ last_name[0][0] = '\0';
+ }
+ }
- if (vb != _last_vehicle) {
- _last_vehicle = vb;
- _bufcache[0] = '\0';
- if (vb->string_id != _internal_name_sorter_id) {
- GetString(_bufcache, vb->string_id);
+ if (vb != last_vehicle[1]) {
+ last_vehicle[1] = vb;
+ if (IsCustomName(vb->string_id)) {
+ GetString(last_name[1], vb->string_id);
+ } else {
+ last_name[1][0] = '\0';
}
}
- r = strcmp(buf1, _bufcache); // sort by name
+ r = strcmp(last_name[0], last_name[1]); // sort by name
VEHICLEUNITNUMBERSORTER(r, va, vb);