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

@@ -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();