diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 35205f56a6..2a62c41c34 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1757,12 +1757,14 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow { const Industry *i = Industry::Get(this->window_number); 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) { if (!IsValidCargoType(p.cargo)) continue; const CargoSpec *cs = CargoSpec::Get(p.cargo); - this->data.reserve(this->data.size() + 2); - DataSet &produced = this->data.emplace_back(); produced.colour = cs->legend_colour; produced.exclude_bit = cs->Index(); @@ -1783,8 +1785,6 @@ struct IndustryProductionGraphWindow : BaseCargoGraphWindow { if (!IsValidCargoType(a.cargo)) continue; const CargoSpec *cs = CargoSpec::Get(a.cargo); - this->data.reserve(this->data.size() + 2); - DataSet &accepted = this->data.emplace_back(); accepted.colour = cs->legend_colour; accepted.exclude_bit = cs->Index();