mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-20 19:02:41 +01:00
Codefix: prevent inefficient reserve behaviour
When reserving by size() + 2, in a loop you're not really helping.
This commit is contained in:
@@ -1757,12 +1757,14 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
|
|||||||
const Industry *i = Industry::Get(this->window_number);
|
const Industry *i = Industry::Get(this->window_number);
|
||||||
|
|
||||||
this->data.clear();
|
this->data.clear();
|
||||||
|
this->data.reserve(
|
||||||
|
2 * std::ranges::count_if(i->produced, &IsValidCargoType, &Industry::ProducedCargo::cargo) +
|
||||||
|
2 * std::ranges::count_if(i->accepted, &IsValidCargoType, &Industry::AcceptedCargo::cargo));
|
||||||
|
|
||||||
for (const auto &p : i->produced) {
|
for (const auto &p : i->produced) {
|
||||||
if (!IsValidCargoType(p.cargo)) continue;
|
if (!IsValidCargoType(p.cargo)) continue;
|
||||||
const CargoSpec *cs = CargoSpec::Get(p.cargo);
|
const CargoSpec *cs = CargoSpec::Get(p.cargo);
|
||||||
|
|
||||||
this->data.reserve(this->data.size() + 2);
|
|
||||||
|
|
||||||
DataSet &produced = this->data.emplace_back();
|
DataSet &produced = this->data.emplace_back();
|
||||||
produced.colour = cs->legend_colour;
|
produced.colour = cs->legend_colour;
|
||||||
produced.exclude_bit = cs->Index();
|
produced.exclude_bit = cs->Index();
|
||||||
@@ -1783,8 +1785,6 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow {
|
|||||||
if (!IsValidCargoType(a.cargo)) continue;
|
if (!IsValidCargoType(a.cargo)) continue;
|
||||||
const CargoSpec *cs = CargoSpec::Get(a.cargo);
|
const CargoSpec *cs = CargoSpec::Get(a.cargo);
|
||||||
|
|
||||||
this->data.reserve(this->data.size() + 2);
|
|
||||||
|
|
||||||
DataSet &accepted = this->data.emplace_back();
|
DataSet &accepted = this->data.emplace_back();
|
||||||
accepted.colour = cs->legend_colour;
|
accepted.colour = cs->legend_colour;
|
||||||
accepted.exclude_bit = cs->Index();
|
accepted.exclude_bit = cs->Index();
|
||||||
|
|||||||
Reference in New Issue
Block a user