From 56356bb761db3cd6fccb291bfedcb9a5d8a83ce0 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 30 May 2024 18:16:13 +0100 Subject: [PATCH] Change container type for several uses of std::map/std::set --- src/bridge_map.cpp | 2 +- src/bridge_signal_map.h | 10 ++++++++-- src/gfx_layout.h | 6 ++++-- src/graph_gui.cpp | 2 +- src/newgrf_gui.cpp | 8 ++++---- src/newgrf_internal.h | 7 ++++--- src/newgrf_spritegroup.cpp | 4 ++-- src/newgrf_spritegroup.h | 8 ++++---- src/script/api/script_error.hpp | 6 +++--- src/sl/vehicle_sl.cpp | 3 ++- src/timer/timer_manager.h | 6 +++--- 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/bridge_map.cpp b/src/bridge_map.cpp index 3081de8175..0716fdd258 100644 --- a/src/bridge_map.cpp +++ b/src/bridge_map.cpp @@ -79,7 +79,7 @@ int GetBridgeHeight(TileIndex t) return h + 1 + ApplyFoundationToSlope(f, tileh); } -std::unordered_map _long_bridge_signal_sim_map; +robin_hood::unordered_flat_map _long_bridge_signal_sim_map; SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal) { diff --git a/src/bridge_signal_map.h b/src/bridge_signal_map.h index 35c2aea78b..35f024b8cd 100644 --- a/src/bridge_signal_map.h +++ b/src/bridge_signal_map.h @@ -15,15 +15,21 @@ #include "signal_type.h" #include "core/bitmath_func.hpp" #include "3rdparty/cpp-btree/btree_set.h" +#include "3rdparty/robin_hood/robin_hood.h" #include -#include struct LongBridgeSignalStorage { std::vector signal_red_bits; + + LongBridgeSignalStorage() = default; + LongBridgeSignalStorage(const LongBridgeSignalStorage &other) = delete; + LongBridgeSignalStorage(LongBridgeSignalStorage &&other) = default; + LongBridgeSignalStorage& operator=(const LongBridgeSignalStorage &other) = delete; + LongBridgeSignalStorage& operator=(LongBridgeSignalStorage &&other) = default; }; -extern std::unordered_map _long_bridge_signal_sim_map; +extern robin_hood::unordered_flat_map _long_bridge_signal_sim_map; extern btree::btree_set _bridge_signal_style_map; diff --git a/src/gfx_layout.h b/src/gfx_layout.h index 5d1f5704dc..cda0ffd2ae 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -14,6 +14,8 @@ #include "gfx_func.h" #include "core/math_func.hpp" +#include "3rdparty/cpp-btree/btree_map.h" + #include #include #include @@ -85,7 +87,7 @@ public: }; /** Mapping from index to font. The pointer is owned by FontColourMap. */ -using FontMap = std::map; +using FontMap = btree::btree_map; /** * Interface to glue fallback and normal layouter into one. @@ -173,7 +175,7 @@ private: static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state); - using FontColourMap = std::map>; + using FontColourMap = btree::btree_map>; static FontColourMap fonts[FS_END]; public: static Font *GetFont(FontSize size, TextColour colour); diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 8df843d72d..e7cbc878fa 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -23,6 +23,7 @@ #include "zoom_func.h" #include "unit_conversion.h" #include "core/math_func.hpp" +#include "station_base.h" #include "widgets/graph_widget.h" @@ -31,7 +32,6 @@ #include #include "safeguards.h" -#include "station_base.h" /* Bitmasks of company and cargo indices that shouldn't be drawn. */ static CompanyMask _legend_excluded_companies; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index 3dd86c71c6..bb9d0e4a91 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -37,7 +37,8 @@ #include "table/sprites.h" -#include +#include "3rdparty/robin_hood/robin_hood.h" + #include #include "safeguards.h" @@ -595,7 +596,7 @@ void ShowNewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c) new NewGRFTextfileWindow(file_type, c); } -typedef std::map GrfIdMap; ///< Map of grfid to the grf config. +typedef robin_hood::unordered_flat_map GrfIdMap; ///< Map of grfid to the grf config. /** * Add all grf configs from \a c into the map. @@ -605,8 +606,7 @@ typedef std::map GrfIdMap; ///< Map of grfid to the static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map) { while (c != nullptr) { - std::pair p(c->ident.grfid, c); - grfid_map->insert(p); + grfid_map->insert({c->ident.grfid, c}); c = c->next; } } diff --git a/src/newgrf_internal.h b/src/newgrf_internal.h index 288fb7a2ef..2121263f72 100644 --- a/src/newgrf_internal.h +++ b/src/newgrf_internal.h @@ -18,6 +18,7 @@ #include "core/arena_alloc.hpp" #include "3rdparty/cpp-btree/btree_map.h" +#include "3rdparty/robin_hood/robin_hood.h" #include #include @@ -68,11 +69,11 @@ public: std::vector spritegroups; /* VarAction2 temporary storage variable tracking */ - btree::btree_map group_temp_store_variable_tracking; + robin_hood::unordered_flat_map group_temp_store_variable_tracking; UniformArenaAllocator group_temp_store_variable_tracking_storage; - btree::btree_map procedure_annotations; + robin_hood::unordered_flat_map procedure_annotations; UniformArenaAllocator procedure_annotations_storage; - btree::btree_map *> inlinable_adjust_groups; + robin_hood::unordered_flat_map *> inlinable_adjust_groups; UniformArenaAllocator), 1024> inlinable_adjust_groups_storage; std::vector dead_store_elimination_candidates; diff --git a/src/newgrf_spritegroup.cpp b/src/newgrf_spritegroup.cpp index 6443f807be..f385d5805b 100644 --- a/src/newgrf_spritegroup.cpp +++ b/src/newgrf_spritegroup.cpp @@ -28,8 +28,8 @@ INSTANTIATE_POOL_METHODS(SpriteGroup) TemporaryStorageArray _temp_store; -std::map _deterministic_sg_shadows; -std::map _randomized_sg_shadows; +robin_hood::unordered_node_map _deterministic_sg_shadows; +robin_hood::unordered_flat_map _randomized_sg_shadows; bool _grfs_loaded_with_sg_shadow_enable = false; GrfSpecFeature GetGrfSpecFeatureForParentScope(GrfSpecFeature feature) diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index f47d8d9a55..1d663f9ce9 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -20,7 +20,7 @@ #include "newgrf_storage.h" #include "newgrf_commons.h" -#include "3rdparty/cpp-btree/btree_set.h" +#include "3rdparty/robin_hood/robin_hood.h" #include #include @@ -541,8 +541,8 @@ protected: const SpriteGroup *Resolve(ResolverObject &object) const override; }; -extern std::map _deterministic_sg_shadows; -extern std::map _randomized_sg_shadows; +extern robin_hood::unordered_node_map _deterministic_sg_shadows; +extern robin_hood::unordered_flat_map _randomized_sg_shadows; extern bool _grfs_loaded_with_sg_shadow_enable; /* This contains a callback result. A failed callback has a value of @@ -779,7 +779,7 @@ private: const SpriteGroup *top_default_group = nullptr; const SpriteGroup *top_graphics_group = nullptr; - btree::btree_set seen_dsgs; + robin_hood::unordered_flat_set seen_dsgs; enum SpriteGroupDumperFlags { SGDF_DEFAULT = 1 << 0, diff --git a/src/script/api/script_error.hpp b/src/script/api/script_error.hpp index ba1e398298..56773b2b60 100644 --- a/src/script/api/script_error.hpp +++ b/src/script/api/script_error.hpp @@ -12,7 +12,7 @@ #include "script_object.hpp" #include "script_companymode.hpp" -#include +#include "../../3rdparty/robin_hood/robin_hood.h" #include /** @@ -221,8 +221,8 @@ public: static void RegisterErrorMapString(ScriptErrorType ai_error_msg, const char *message); private: - typedef std::map ScriptErrorMap; ///< The type for mapping between error (internal OpenTTD) StringID to the script error type. - typedef std::map ScriptErrorMapString; ///< The type for mapping between error type and textual representation. + typedef robin_hood::unordered_flat_map ScriptErrorMap; ///< The type for mapping between error (internal OpenTTD) StringID to the script error type. + typedef robin_hood::unordered_flat_map ScriptErrorMapString; ///< The type for mapping between error type and textual representation. static ScriptErrorMap error_map; ///< The mapping between error (internal OpenTTD) StringID to the script error type. static ScriptErrorMapString error_map_string; ///< The mapping between error type and textual representation. diff --git a/src/sl/vehicle_sl.cpp b/src/sl/vehicle_sl.cpp index da21a06b6e..27268c75ea 100644 --- a/src/sl/vehicle_sl.cpp +++ b/src/sl/vehicle_sl.cpp @@ -25,6 +25,7 @@ #include "../economy_base.h" #include "../event_logs.h" #include "../3rdparty/cpp-btree/btree_map.h" +#include "../3rdparty/robin_hood/robin_hood.h" #include "../core/format.hpp" #include "saveload.h" @@ -296,7 +297,7 @@ void AfterLoadVehicles(bool part_of_load) * a) both next_shared and previous_shared are not set for pre 5,2 games * b) both next_shared and previous_shared are set for later games */ - std::map mapping; + robin_hood::unordered_flat_map mapping; for (Vehicle *v : Vehicle::Iterate()) { si_v = v; diff --git a/src/timer/timer_manager.h b/src/timer/timer_manager.h index b1f3db46f0..75493edfc9 100644 --- a/src/timer/timer_manager.h +++ b/src/timer/timer_manager.h @@ -12,7 +12,7 @@ #define TIMER_MANAGER_H #include "../stdafx.h" -#include +#include "../3rdparty/cpp-btree/btree_set.h" template class BaseTimer; @@ -112,9 +112,9 @@ private: }; /** Singleton list, to store all the active timers. */ - static std::set *, base_timer_sorter> &GetTimers() + static btree::btree_set *, base_timer_sorter> &GetTimers() { - static std::set *, base_timer_sorter> timers; + static btree::btree_set *, base_timer_sorter> timers; return timers; } };