From dc15cd30e8e84a3cdb0a6081c0b5832f08d8516e Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 11 Jan 2026 09:56:17 +0000 Subject: [PATCH] Codefix: prevent inefficient reserve behaviour (#15081) Same as d3420e6e4c but for Town instead of Industry graph. --- src/graph_gui.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 543f7a2055..e54f736238 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -1923,12 +1923,13 @@ struct TownCargoGraphWindow : BaseCargoGraphWindow { const Town *t = Town::Get(this->window_number); this->data.clear(); + this->data.reserve( + 2 * std::ranges::count_if(t->supplied, &IsValidCargoType, &Town::SuppliedCargo::cargo)); + for (const auto &s : t->supplied) { if (!IsValidCargoType(s.cargo)) continue; const CargoSpec *cs = CargoSpec::Get(s.cargo); - this->data.reserve(this->data.size() + 2); - DataSet &produced = this->data.emplace_back(); produced.colour = cs->legend_colour; produced.exclude_bit = cs->Index();