mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::string to cache engine/group/vehicle names
parent
d9f8a4c380
commit
f29606fd14
|
@ -145,19 +145,18 @@ static EngineID _last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
|
||||||
*/
|
*/
|
||||||
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
|
static bool EngineNameSorter(const GUIEngineListItem &a, const GUIEngineListItem &b)
|
||||||
{
|
{
|
||||||
static char last_name[2][64] = { "", "" };
|
static std::string last_name[2] = { {}, {} };
|
||||||
|
|
||||||
if (a.engine_id != _last_engine[0]) {
|
if (a.engine_id != _last_engine[0]) {
|
||||||
_last_engine[0] = a.engine_id;
|
_last_engine[0] = a.engine_id;
|
||||||
SetDParam(0, PackEngineNameDParam(a.engine_id, EngineNameContext::PurchaseList));
|
SetDParam(0, PackEngineNameDParam(a.engine_id, EngineNameContext::PurchaseList));
|
||||||
|
last_name[0] = GetString(STR_ENGINE_NAME);
|
||||||
GetString(last_name[0], STR_ENGINE_NAME, lastof(last_name[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.engine_id != _last_engine[1]) {
|
if (b.engine_id != _last_engine[1]) {
|
||||||
_last_engine[1] = b.engine_id;
|
_last_engine[1] = b.engine_id;
|
||||||
SetDParam(0, PackEngineNameDParam(b.engine_id, EngineNameContext::PurchaseList));
|
SetDParam(0, PackEngineNameDParam(b.engine_id, EngineNameContext::PurchaseList));
|
||||||
GetString(last_name[1], STR_ENGINE_NAME, lastof(last_name[1]));
|
last_name[1] = GetString(STR_ENGINE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||||
|
|
|
@ -721,18 +721,18 @@ private:
|
||||||
|
|
||||||
/* Sort the groups by their name */
|
/* Sort the groups by their name */
|
||||||
const Group *last_group[2] = { nullptr, nullptr };
|
const Group *last_group[2] = { nullptr, nullptr };
|
||||||
char last_name[2][64] = { "", "" };
|
std::string last_name[2] = { {}, {} };
|
||||||
list.Sort([&](const Group * const &a, const Group * const &b) -> bool {
|
list.Sort([&](const Group * const &a, const Group * const &b) -> bool {
|
||||||
if (a != last_group[0]) {
|
if (a != last_group[0]) {
|
||||||
last_group[0] = a;
|
last_group[0] = a;
|
||||||
SetDParam(0, a->index);
|
SetDParam(0, a->index);
|
||||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
last_name[0] = GetString(STR_GROUP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b != last_group[1]) {
|
if (b != last_group[1]) {
|
||||||
last_group[1] = b;
|
last_group[1] = b;
|
||||||
SetDParam(0, b->index);
|
SetDParam(0, b->index);
|
||||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
last_name[1] = GetString(STR_GROUP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||||
|
|
|
@ -177,18 +177,18 @@ private:
|
||||||
|
|
||||||
/* Sort the groups by their name */
|
/* Sort the groups by their name */
|
||||||
const Group *last_group[2] = { nullptr, nullptr };
|
const Group *last_group[2] = { nullptr, nullptr };
|
||||||
char last_name[2][64] = { "", "" };
|
std::string last_name[2] = { {}, {} };
|
||||||
list.Sort([&](const Group * const &a, const Group * const &b) {
|
list.Sort([&](const Group * const &a, const Group * const &b) {
|
||||||
if (a != last_group[0]) {
|
if (a != last_group[0]) {
|
||||||
last_group[0] = a;
|
last_group[0] = a;
|
||||||
SetDParam(0, a->index);
|
SetDParam(0, a->index);
|
||||||
GetString(last_name[0], STR_GROUP_NAME, lastof(last_name[0]));
|
last_name[0] = GetString(STR_GROUP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b != last_group[1]) {
|
if (b != last_group[1]) {
|
||||||
last_group[1] = b;
|
last_group[1] = b;
|
||||||
SetDParam(0, b->index);
|
SetDParam(0, b->index);
|
||||||
GetString(last_name[1], STR_GROUP_NAME, lastof(last_name[1]));
|
last_name[1] = GetString(STR_GROUP_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||||
|
|
|
@ -1332,18 +1332,18 @@ static bool VehicleNumberSorter(const Vehicle * const &a, const Vehicle * const
|
||||||
/** Sort vehicles by their name */
|
/** Sort vehicles by their name */
|
||||||
static bool VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b)
|
static bool VehicleNameSorter(const Vehicle * const &a, const Vehicle * const &b)
|
||||||
{
|
{
|
||||||
static char last_name[2][64];
|
static std::string last_name[2] = { {}, {} };
|
||||||
|
|
||||||
if (a != _last_vehicle[0]) {
|
if (a != _last_vehicle[0]) {
|
||||||
_last_vehicle[0] = a;
|
_last_vehicle[0] = a;
|
||||||
SetDParam(0, a->index);
|
SetDParam(0, a->index);
|
||||||
GetString(last_name[0], STR_VEHICLE_NAME, lastof(last_name[0]));
|
last_name[0] = GetString(STR_VEHICLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b != _last_vehicle[1]) {
|
if (b != _last_vehicle[1]) {
|
||||||
_last_vehicle[1] = b;
|
_last_vehicle[1] = b;
|
||||||
SetDParam(0, b->index);
|
SetDParam(0, b->index);
|
||||||
GetString(last_name[1], STR_VEHICLE_NAME, lastof(last_name[1]));
|
last_name[1] = GetString(STR_VEHICLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
int r = StrNaturalCompare(last_name[0], last_name[1]); // Sort by name (natural sorting).
|
||||||
|
|
Loading…
Reference in New Issue