Codechange: Replace GroupStatistics' num_engines with std::map. (#11849)

This removes manual memory management with calloc/free calls, and prevents potentially large arrays being allocated for each group.
This commit is contained in:
Peter Nelson
2024-01-21 14:09:44 +00:00
committed by GitHub
parent c0ab436077
commit 8797cc7ef2
3 changed files with 19 additions and 19 deletions

View File

@@ -24,15 +24,12 @@ extern GroupPool _group_pool; ///< Pool of groups.
struct GroupStatistics {
Money profit_last_year; ///< Sum of profits for all vehicles.
Money profit_last_year_min_age; ///< Sum of profits for vehicles considered for profit statistics.
uint16_t *num_engines; ///< Caches the number of engines of each type the company owns.
std::map<EngineID, uint16_t> num_engines; ///< Caches the number of engines of each type the company owns.
uint16_t num_vehicle; ///< Number of vehicles.
uint16_t num_vehicle_min_age; ///< Number of vehicles considered for profit statistics;
bool autoreplace_defined; ///< Are any autoreplace rules set?
bool autoreplace_finished; ///< Have all autoreplacement finished?
GroupStatistics();
~GroupStatistics();
void Clear();
void ClearProfits()
@@ -49,6 +46,8 @@ struct GroupStatistics {
this->autoreplace_finished = false;
}
uint16_t GetNumEngines(EngineID engine) const;
static GroupStatistics &Get(CompanyID company, GroupID id_g, VehicleType type);
static GroupStatistics &Get(const Vehicle *v);
static GroupStatistics &GetAllGroup(const Vehicle *v);