1
0
Fork 0

Codechange: Use .fill() to clear an array instead of assigning a new array. (#13880)

Avoids allocating a temporary on the stack.
pull/13848/head
Peter Nelson 2025-03-23 22:09:45 +00:00 committed by GitHub
parent ca801d55d5
commit fc7b6c6cbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 5 additions and 5 deletions

View File

@ -787,7 +787,7 @@ static IntervalTimer<TimerGameEconomy> _economy_companies_yearly({TimerGameEcono
for (Company *c : Company::Iterate()) { for (Company *c : Company::Iterate()) {
/* Move expenses to previous years. */ /* Move expenses to previous years. */
std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses)); std::rotate(std::rbegin(c->yearly_expenses), std::rbegin(c->yearly_expenses) + 1, std::rend(c->yearly_expenses));
c->yearly_expenses[0] = {}; c->yearly_expenses[0].fill(0);
InvalidateWindowData(WC_FINANCES, c->index); InvalidateWindowData(WC_FINANCES, c->index);
} }

View File

@ -204,7 +204,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
Owner owner = c->index; Owner owner = c->index;
int score = 0; int score = 0;
_score_part[owner] = {}; _score_part[owner].fill(0);
/* Count vehicles */ /* Count vehicles */
{ {

View File

@ -3072,7 +3072,7 @@ static IntervalTimer<TimerGameEconomy> _economy_industries_monthly({TimerGameEco
void InitializeIndustries() void InitializeIndustries()
{ {
Industry::industries = {}; Industry::industries.fill({});
_industry_sound_tile = TileIndex{}; _industry_sound_tile = TileIndex{};
_industry_builder.Reset(); _industry_builder.Reset();

View File

@ -675,8 +675,8 @@ static void UpdateVehicleViewportHash(Vehicle *v, int x, int y, int old_x, int o
void ResetVehicleHash() void ResetVehicleHash()
{ {
for (Vehicle *v : Vehicle::Iterate()) { v->hash_tile_current = nullptr; } for (Vehicle *v : Vehicle::Iterate()) { v->hash_tile_current = nullptr; }
_vehicle_viewport_hash = {}; _vehicle_viewport_hash.fill(nullptr);
_vehicle_tile_hash = {}; _vehicle_tile_hash.fill(nullptr);
} }
void ResetVehicleColourMap() void ResetVehicleColourMap()