diff options
author | Jonathan G Rennison <j.g.rennison@gmail.com> | 2020-01-06 20:40:31 +0000 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2020-01-12 19:37:43 +0000 |
commit | c3223903ed4f39abe8589355882b30b973da434e (patch) | |
tree | 9876dda172d7a076d7724efc52e21302bb7696a7 /src/base_station_base.h | |
parent | f1734e7815653829d42ebd4def8c0d7d5aeae986 (diff) | |
download | openttd-c3223903ed4f39abe8589355882b30b973da434e.tar.xz |
Codechange: Cache resolved town, station and industry name strings
Diffstat (limited to 'src/base_station_base.h')
-rw-r--r-- | src/base_station_base.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/base_station_base.h b/src/base_station_base.h index a1c935fce..0467866e5 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -56,6 +56,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { char *name; ///< Custom name StringID string_id; ///< Default name (town area) of station + mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the station, if not using a custom name Town *town; ///< The town this station is associated with Owner owner; ///< The owner of this station @@ -108,6 +109,13 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { */ virtual void UpdateVirtCoord() = 0; + inline const char *GetCachedName() const + { + if (this->name != nullptr) return this->name; + if (this->cached_name.empty()) this->FillCachedName(); + return this->cached_name.c_str(); + } + virtual void MoveSign(TileIndex new_xy) { this->xy = new_xy; @@ -161,6 +169,9 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { } static void PostDestructor(size_t index); + +private: + void FillCachedName() const; }; /** |