Improve performance of name sorting in industry list window

This commit is contained in:
Jonathan G Rennison
2019-05-12 18:55:25 +01:00
parent f6b9395c6a
commit b91ee6fb4b
5 changed files with 34 additions and 13 deletions

View File

@@ -1253,19 +1253,7 @@ protected:
/** Sort industries by name */
static bool IndustryNameSorter(const Industry * const &a, const Industry * const &b)
{
static char buf_cache[96];
static char buf[96];
SetDParam(0, a->index);
GetString(buf, STR_INDUSTRY_NAME, lastof(buf));
if (b != last_industry) {
last_industry = b;
SetDParam(0, b->index);
GetString(buf_cache, STR_INDUSTRY_NAME, lastof(buf_cache));
}
return strnatcmp(buf, buf_cache) < 0; // Sort by name (natural sorting).
return strnatcmp(a->GetCachedName(), b->GetCachedName()) < 0; // Sort by name (natural sorting).
}
/** Sort industries by type and name */