Improve performance of name sorting in town and station list windows
This commit is contained in:
@@ -229,6 +229,15 @@ void Town::UpdateLabel()
|
||||
}
|
||||
}
|
||||
|
||||
void Town::FillCachedName()
|
||||
{
|
||||
char buf[256];
|
||||
char *end = GetTownName(buf, this, lastof(buf));
|
||||
char *alloced = MallocT<char>(end - buf + 1);
|
||||
memcpy(alloced, buf, end - buf + 1);
|
||||
this->cached_name.reset(alloced);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cost for removing this house
|
||||
* @return the cost (inflation corrected etc)
|
||||
@@ -522,6 +531,15 @@ void UpdateAllTownVirtCoords()
|
||||
}
|
||||
}
|
||||
|
||||
void ClearAllTownCachedNames()
|
||||
{
|
||||
Town *t;
|
||||
|
||||
FOR_ALL_TOWNS(t) {
|
||||
t->cached_name.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the towns population
|
||||
* @param t Town which population has changed
|
||||
@@ -2863,11 +2881,13 @@ CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
t->cached_name.reset();
|
||||
free(t->name);
|
||||
t->name = reset ? nullptr : stredup(text);
|
||||
|
||||
t->UpdateVirtCoord();
|
||||
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 1);
|
||||
ClearAllStationCachedNames();
|
||||
UpdateAllStationVirtCoords();
|
||||
}
|
||||
return CommandCost();
|
||||
|
Reference in New Issue
Block a user