Improve performance of name sorting in town and station list windows
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
#include "viewport_type.h"
|
||||
#include "station_map.h"
|
||||
#include "core/geometry_type.hpp"
|
||||
#include "core/alloc_type.hpp"
|
||||
#include <memory>
|
||||
|
||||
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
||||
extern StationPool _station_pool;
|
||||
@@ -59,6 +61,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||
|
||||
char *name; ///< Custom name
|
||||
StringID string_id; ///< Default name (town area) of station
|
||||
std::unique_ptr<const char, FreeDeleter> 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
|
||||
OwnerByte owner; ///< The owner of this station
|
||||
@@ -113,6 +116,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) const_cast<BaseStation *>(this)->FillCachedName();
|
||||
return this->cached_name.get();
|
||||
}
|
||||
|
||||
virtual void MoveSign(TileIndex new_xy)
|
||||
{
|
||||
this->xy = new_xy;
|
||||
@@ -176,6 +186,9 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||
}
|
||||
|
||||
static void PostDestructor(size_t index);
|
||||
|
||||
private:
|
||||
void FillCachedName();
|
||||
};
|
||||
|
||||
#define FOR_ALL_BASE_STATIONS(var) FOR_ALL_ITEMS_FROM(BaseStation, station_index, var, 0)
|
||||
|
||||
Reference in New Issue
Block a user