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

@@ -64,6 +64,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy?
StationList stations_near; ///< NOSAVE: List of nearby stations.
std::unique_ptr<const char, FreeDeleter> cached_name; ///< NOSAVE: Cache of the resolved name of the industry
OwnerByte founder; ///< Founder of the industry
Date construction_date; ///< Date of the construction of the industry
@@ -159,10 +160,21 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
memset(&counts, 0, sizeof(counts));
}
inline const char *GetCachedName() const
{
if (!this->cached_name) const_cast<Industry *>(this)->FillCachedName();
return this->cached_name.get();
}
private:
void FillCachedName();
protected:
static uint16 counts[NUM_INDUSTRYTYPES]; ///< Number of industries per type ingame
};
void ClearAllIndustryCachedNames();
void PlantRandomFarmField(const Industry *i);
void ReleaseDisastersTargetingIndustry(IndustryID);