From 4d4096630378477528e2d045b3805b0df8ecf830 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 7 Sep 2025 14:13:57 +0100 Subject: [PATCH] Codechange: Use FlatSet to store and test alternate rail/road types. --- src/newgrf/newgrf_act0_railtypes.cpp | 2 +- src/newgrf/newgrf_act0_roadtypes.cpp | 2 +- src/rail.cpp | 3 +-- src/rail.h | 3 ++- src/road.cpp | 3 +-- src/road.h | 3 ++- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/newgrf/newgrf_act0_railtypes.cpp b/src/newgrf/newgrf_act0_railtypes.cpp index 27394f8bf4..d37a3684ec 100644 --- a/src/newgrf/newgrf_act0_railtypes.cpp +++ b/src/newgrf/newgrf_act0_railtypes.cpp @@ -204,7 +204,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint first, uint last, int prop, Byt if (type_map[id] != INVALID_RAILTYPE) { int n = buf.ReadByte(); for (int j = 0; j != n; j++) { - _railtypes[type_map[id]].alternate_labels.push_back(std::byteswap(buf.ReadDWord())); + _railtypes[type_map[id]].alternate_labels.insert(std::byteswap(buf.ReadDWord())); } break; } diff --git a/src/newgrf/newgrf_act0_roadtypes.cpp b/src/newgrf/newgrf_act0_roadtypes.cpp index 2eff6b05fd..4fa5746ce9 100644 --- a/src/newgrf/newgrf_act0_roadtypes.cpp +++ b/src/newgrf/newgrf_act0_roadtypes.cpp @@ -192,7 +192,7 @@ static ChangeInfoResult RoadTypeReserveInfo(uint first, uint last, int prop, Byt if (type_map[id] != INVALID_ROADTYPE) { int n = buf.ReadByte(); for (int j = 0; j != n; j++) { - _roadtypes[type_map[id]].alternate_labels.push_back(std::byteswap(buf.ReadDWord())); + _roadtypes[type_map[id]].alternate_labels.insert(std::byteswap(buf.ReadDWord())); } break; } diff --git a/src/rail.cpp b/src/rail.cpp index 590676aa87..7e7174fef2 100644 --- a/src/rail.cpp +++ b/src/rail.cpp @@ -205,8 +205,7 @@ RailType GetRailTypeByLabel(RailTypeLabel label, bool allow_alternate_labels) if (allow_alternate_labels) { /* Test if any rail type defines the label as an alternate. */ for (RailType r = RAILTYPE_BEGIN; r != RAILTYPE_END; r++) { - const RailTypeInfo *rti = GetRailTypeInfo(r); - if (std::ranges::find(rti->alternate_labels, label) != rti->alternate_labels.end()) return r; + if (GetRailTypeInfo(r)->alternate_labels.contains(label)) return r; } } diff --git a/src/rail.h b/src/rail.h index b65f2351c8..9865f81003 100644 --- a/src/rail.h +++ b/src/rail.h @@ -15,6 +15,7 @@ #include "gfx_type.h" #include "core/bitmath_func.hpp" #include "core/enum_type.hpp" +#include "core/flatset_type.hpp" #include "economy_func.h" #include "slope_type.h" #include "strings_type.h" @@ -227,7 +228,7 @@ public: /** * Rail type labels this type provides in addition to the main label. */ - std::vector alternate_labels; + FlatSet alternate_labels; /** * Colour on mini-map diff --git a/src/road.cpp b/src/road.cpp index 51bdf1900d..590abfa07c 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -275,8 +275,7 @@ RoadType GetRoadTypeByLabel(RoadTypeLabel label, bool allow_alternate_labels) if (allow_alternate_labels) { /* Test if any road type defines the label as an alternate. */ for (RoadType r = ROADTYPE_BEGIN; r != ROADTYPE_END; r++) { - const RoadTypeInfo *rti = GetRoadTypeInfo(r); - if (std::ranges::find(rti->alternate_labels, label) != rti->alternate_labels.end()) return r; + if (GetRoadTypeInfo(r)->alternate_labels.contains(label)) return r; } } diff --git a/src/road.h b/src/road.h index a3c689419f..b67df0e70a 100644 --- a/src/road.h +++ b/src/road.h @@ -13,6 +13,7 @@ #include "road_type.h" #include "gfx_type.h" #include "core/bitmath_func.hpp" +#include "core/flatset_type.hpp" #include "strings_type.h" #include "timer/timer_game_calendar.h" #include "core/enum_type.hpp" @@ -137,7 +138,7 @@ public: /** * Road type labels this type provides in addition to the main label. */ - std::vector alternate_labels; + FlatSet alternate_labels; /** * Colour on mini-map