1
0
Fork 0

Codechange: Use FlatSet when filtering and drawing badge names.

pull/14219/head
Peter Nelson 2025-04-13 10:06:35 +01:00 committed by Peter Nelson
parent 5fd7344a6d
commit 7679b0bc46
3 changed files with 5 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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<const BadgeID> badges) const;
private:
std::vector<BadgeID> badges{};
FlatSet<BadgeID> badges{};
};
#endif /* NEWGRF_BADGE_H */

View File

@ -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<const BadgeID> badges, GrfSpecFeature)
{
if (badges.empty()) return r.top;
std::set<BadgeClassID> class_indexes;
FlatSet<BadgeClassID> class_indexes;
for (const BadgeID &index : badges) class_indexes.insert(GetBadge(index)->class_index);
std::string_view list_separator = GetListSeparator();