Improve performance of name sorting in town and station list windows

This commit is contained in:
Jonathan G Rennison
2019-05-12 18:03:57 +01:00
parent 748d73079a
commit f6b9395c6a
10 changed files with 81 additions and 38 deletions

View File

@@ -456,6 +456,26 @@ void UpdateAllStationVirtCoords()
}
}
void BaseStation::FillCachedName()
{
char buf[256];
int64 args_array[] = { this->index };
StringParameters tmp_params(args_array);
char *end = GetStringWithArgs(buf, Waypoint::IsExpected(this) ? STR_WAYPOINT_NAME : STR_STATION_NAME, &tmp_params, lastof(buf));
char *alloced = MallocT<char>(end - buf + 1);
memcpy(alloced, buf, end - buf + 1);
this->cached_name.reset(alloced);
}
void ClearAllStationCachedNames()
{
BaseStation *st;
FOR_ALL_BASE_STATIONS(st) {
st->cached_name.reset();
}
}
/**
* Get a mask of the cargo types that the station accepts.
* @param st Station to query
@@ -4006,6 +4026,7 @@ CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
}
if (flags & DC_EXEC) {
st->cached_name.reset();
free(st->name);
st->name = reset ? nullptr : stredup(text);