From 7679b0bc46a810371e718b4b5ce74e3e2ab2c902 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 13 Apr 2025 10:06:35 +0100 Subject: [PATCH] Codechange: Use FlatSet when filtering and drawing badge names. --- src/newgrf_badge.cpp | 5 +---- src/newgrf_badge.h | 3 ++- src/newgrf_badge_gui.cpp | 3 ++- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/newgrf_badge.cpp b/src/newgrf_badge.cpp index 9a01139be1..ee0b39742c 100644 --- a/src/newgrf_badge.cpp +++ b/src/newgrf_badge.cpp @@ -318,10 +318,7 @@ BadgeTextFilter::BadgeTextFilter(StringFilter &filter, GrfSpecFeature feature) filter.AddLine(GetString(badge.name)); if (!filter.GetState()) continue; - auto it = std::ranges::lower_bound(this->badges, badge.index); - if (it != std::end(this->badges) && *it == badge.index) continue; - - this->badges.insert(it, badge.index); + this->badges.insert(badge.index); } } diff --git a/src/newgrf_badge.h b/src/newgrf_badge.h index dca2bd6995..684bf08a5b 100644 --- a/src/newgrf_badge.h +++ b/src/newgrf_badge.h @@ -10,6 +10,7 @@ #ifndef NEWGRF_BADGE_H #define NEWGRF_BADGE_H +#include "core/flatset_type.hpp" #include "newgrf.h" #include "newgrf_badge_type.h" #include "newgrf_commons.h" @@ -65,7 +66,7 @@ public: bool Filter(std::span badges) const; private: - std::vector badges{}; + FlatSet badges{}; }; #endif /* NEWGRF_BADGE_H */ diff --git a/src/newgrf_badge_gui.cpp b/src/newgrf_badge_gui.cpp index a65b06ff11..59bcbdb427 100644 --- a/src/newgrf_badge_gui.cpp +++ b/src/newgrf_badge_gui.cpp @@ -9,6 +9,7 @@ #include "stdafx.h" +#include "core/flatset_type.hpp" #include "dropdown_type.h" #include "newgrf.h" #include "newgrf_badge.h" @@ -120,7 +121,7 @@ int DrawBadgeNameList(Rect r, std::span badges, GrfSpecFeature) { if (badges.empty()) return r.top; - std::set class_indexes; + FlatSet class_indexes; for (const BadgeID &index : badges) class_indexes.insert(GetBadge(index)->class_index); std::string_view list_separator = GetListSeparator();