Change container type for several uses of std::map/std::set

This commit is contained in:
Jonathan G Rennison
2024-05-30 18:16:13 +01:00
parent 853ed272be
commit 56356bb761
11 changed files with 36 additions and 26 deletions

View File

@@ -79,7 +79,7 @@ int GetBridgeHeight(TileIndex t)
return h + 1 + ApplyFoundationToSlope(f, tileh); return h + 1 + ApplyFoundationToSlope(f, tileh);
} }
std::unordered_map<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map; robin_hood::unordered_flat_map<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map;
SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal) SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16_t signal)
{ {

View File

@@ -15,15 +15,21 @@
#include "signal_type.h" #include "signal_type.h"
#include "core/bitmath_func.hpp" #include "core/bitmath_func.hpp"
#include "3rdparty/cpp-btree/btree_set.h" #include "3rdparty/cpp-btree/btree_set.h"
#include "3rdparty/robin_hood/robin_hood.h"
#include <vector> #include <vector>
#include <unordered_map>
struct LongBridgeSignalStorage { struct LongBridgeSignalStorage {
std::vector<uint64_t> signal_red_bits; std::vector<uint64_t> 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<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map; extern robin_hood::unordered_flat_map<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map;
extern btree::btree_set<uint32_t> _bridge_signal_style_map; extern btree::btree_set<uint32_t> _bridge_signal_style_map;

View File

@@ -14,6 +14,8 @@
#include "gfx_func.h" #include "gfx_func.h"
#include "core/math_func.hpp" #include "core/math_func.hpp"
#include "3rdparty/cpp-btree/btree_map.h"
#include <map> #include <map>
#include <string> #include <string>
#include <stack> #include <stack>
@@ -85,7 +87,7 @@ public:
}; };
/** Mapping from index to font. The pointer is owned by FontColourMap. */ /** Mapping from index to font. The pointer is owned by FontColourMap. */
using FontMap = std::map<int, Font *>; using FontMap = btree::btree_map<int, Font *>;
/** /**
* Interface to glue fallback and normal layouter into one. * Interface to glue fallback and normal layouter into one.
@@ -173,7 +175,7 @@ private:
static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state); static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state);
using FontColourMap = std::map<TextColour, std::unique_ptr<Font>>; using FontColourMap = btree::btree_map<TextColour, std::unique_ptr<Font>>;
static FontColourMap fonts[FS_END]; static FontColourMap fonts[FS_END];
public: public:
static Font *GetFont(FontSize size, TextColour colour); static Font *GetFont(FontSize size, TextColour colour);

View File

@@ -23,6 +23,7 @@
#include "zoom_func.h" #include "zoom_func.h"
#include "unit_conversion.h" #include "unit_conversion.h"
#include "core/math_func.hpp" #include "core/math_func.hpp"
#include "station_base.h"
#include "widgets/graph_widget.h" #include "widgets/graph_widget.h"
@@ -31,7 +32,6 @@
#include <math.h> #include <math.h>
#include "safeguards.h" #include "safeguards.h"
#include "station_base.h"
/* Bitmasks of company and cargo indices that shouldn't be drawn. */ /* Bitmasks of company and cargo indices that shouldn't be drawn. */
static CompanyMask _legend_excluded_companies; static CompanyMask _legend_excluded_companies;

View File

@@ -37,7 +37,8 @@
#include "table/sprites.h" #include "table/sprites.h"
#include <map> #include "3rdparty/robin_hood/robin_hood.h"
#include <numeric> #include <numeric>
#include "safeguards.h" #include "safeguards.h"
@@ -595,7 +596,7 @@ void ShowNewGRFTextfileWindow(TextfileType file_type, const GRFConfig *c)
new NewGRFTextfileWindow(file_type, c); new NewGRFTextfileWindow(file_type, c);
} }
typedef std::map<uint32_t, const GRFConfig *> GrfIdMap; ///< Map of grfid to the grf config. typedef robin_hood::unordered_flat_map<uint32_t, const GRFConfig *> GrfIdMap; ///< Map of grfid to the grf config.
/** /**
* Add all grf configs from \a c into the map. * Add all grf configs from \a c into the map.
@@ -605,8 +606,7 @@ typedef std::map<uint32_t, const GRFConfig *> GrfIdMap; ///< Map of grfid to the
static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map) static void FillGrfidMap(const GRFConfig *c, GrfIdMap *grfid_map)
{ {
while (c != nullptr) { while (c != nullptr) {
std::pair<uint32_t, const GRFConfig *> p(c->ident.grfid, c); grfid_map->insert({c->ident.grfid, c});
grfid_map->insert(p);
c = c->next; c = c->next;
} }
} }

View File

@@ -18,6 +18,7 @@
#include "core/arena_alloc.hpp" #include "core/arena_alloc.hpp"
#include "3rdparty/cpp-btree/btree_map.h" #include "3rdparty/cpp-btree/btree_map.h"
#include "3rdparty/robin_hood/robin_hood.h"
#include <bitset> #include <bitset>
#include <vector> #include <vector>
@@ -68,11 +69,11 @@ public:
std::vector<const SpriteGroup *> spritegroups; std::vector<const SpriteGroup *> spritegroups;
/* VarAction2 temporary storage variable tracking */ /* VarAction2 temporary storage variable tracking */
btree::btree_map<const SpriteGroup *, VarAction2GroupVariableTracking *> group_temp_store_variable_tracking; robin_hood::unordered_flat_map<const SpriteGroup *, VarAction2GroupVariableTracking *> group_temp_store_variable_tracking;
UniformArenaAllocator<sizeof(VarAction2GroupVariableTracking), 1024> group_temp_store_variable_tracking_storage; UniformArenaAllocator<sizeof(VarAction2GroupVariableTracking), 1024> group_temp_store_variable_tracking_storage;
btree::btree_map<const SpriteGroup *, VarAction2ProcedureAnnotation *> procedure_annotations; robin_hood::unordered_flat_map<const SpriteGroup *, VarAction2ProcedureAnnotation *> procedure_annotations;
UniformArenaAllocator<sizeof(VarAction2ProcedureAnnotation), 1024> procedure_annotations_storage; UniformArenaAllocator<sizeof(VarAction2ProcedureAnnotation), 1024> procedure_annotations_storage;
btree::btree_map<const DeterministicSpriteGroup *, std::vector<DeterministicSpriteGroupAdjust> *> inlinable_adjust_groups; robin_hood::unordered_flat_map<const DeterministicSpriteGroup *, std::vector<DeterministicSpriteGroupAdjust> *> inlinable_adjust_groups;
UniformArenaAllocator<sizeof(std::vector<DeterministicSpriteGroupAdjust>), 1024> inlinable_adjust_groups_storage; UniformArenaAllocator<sizeof(std::vector<DeterministicSpriteGroupAdjust>), 1024> inlinable_adjust_groups_storage;
std::vector<DeterministicSpriteGroup *> dead_store_elimination_candidates; std::vector<DeterministicSpriteGroup *> dead_store_elimination_candidates;

View File

@@ -28,8 +28,8 @@ INSTANTIATE_POOL_METHODS(SpriteGroup)
TemporaryStorageArray<int32_t, 0x110> _temp_store; TemporaryStorageArray<int32_t, 0x110> _temp_store;
std::map<const DeterministicSpriteGroup *, DeterministicSpriteGroupShadowCopy> _deterministic_sg_shadows; robin_hood::unordered_node_map<const DeterministicSpriteGroup *, DeterministicSpriteGroupShadowCopy> _deterministic_sg_shadows;
std::map<const RandomizedSpriteGroup *, RandomizedSpriteGroupShadowCopy> _randomized_sg_shadows; robin_hood::unordered_flat_map<const RandomizedSpriteGroup *, RandomizedSpriteGroupShadowCopy> _randomized_sg_shadows;
bool _grfs_loaded_with_sg_shadow_enable = false; bool _grfs_loaded_with_sg_shadow_enable = false;
GrfSpecFeature GetGrfSpecFeatureForParentScope(GrfSpecFeature feature) GrfSpecFeature GetGrfSpecFeatureForParentScope(GrfSpecFeature feature)

View File

@@ -20,7 +20,7 @@
#include "newgrf_storage.h" #include "newgrf_storage.h"
#include "newgrf_commons.h" #include "newgrf_commons.h"
#include "3rdparty/cpp-btree/btree_set.h" #include "3rdparty/robin_hood/robin_hood.h"
#include <map> #include <map>
#include <vector> #include <vector>
@@ -541,8 +541,8 @@ protected:
const SpriteGroup *Resolve(ResolverObject &object) const override; const SpriteGroup *Resolve(ResolverObject &object) const override;
}; };
extern std::map<const DeterministicSpriteGroup *, DeterministicSpriteGroupShadowCopy> _deterministic_sg_shadows; extern robin_hood::unordered_node_map<const DeterministicSpriteGroup *, DeterministicSpriteGroupShadowCopy> _deterministic_sg_shadows;
extern std::map<const RandomizedSpriteGroup *, RandomizedSpriteGroupShadowCopy> _randomized_sg_shadows; extern robin_hood::unordered_flat_map<const RandomizedSpriteGroup *, RandomizedSpriteGroupShadowCopy> _randomized_sg_shadows;
extern bool _grfs_loaded_with_sg_shadow_enable; extern bool _grfs_loaded_with_sg_shadow_enable;
/* This contains a callback result. A failed callback has a value of /* 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_default_group = nullptr;
const SpriteGroup *top_graphics_group = nullptr; const SpriteGroup *top_graphics_group = nullptr;
btree::btree_set<const DeterministicSpriteGroup *> seen_dsgs; robin_hood::unordered_flat_set<const DeterministicSpriteGroup *> seen_dsgs;
enum SpriteGroupDumperFlags { enum SpriteGroupDumperFlags {
SGDF_DEFAULT = 1 << 0, SGDF_DEFAULT = 1 << 0,

View File

@@ -12,7 +12,7 @@
#include "script_object.hpp" #include "script_object.hpp"
#include "script_companymode.hpp" #include "script_companymode.hpp"
#include <map> #include "../../3rdparty/robin_hood/robin_hood.h"
#include <optional> #include <optional>
/** /**
@@ -221,8 +221,8 @@ public:
static void RegisterErrorMapString(ScriptErrorType ai_error_msg, const char *message); static void RegisterErrorMapString(ScriptErrorType ai_error_msg, const char *message);
private: private:
typedef std::map<StringID, ScriptErrorType> ScriptErrorMap; ///< The type for mapping between error (internal OpenTTD) StringID to the script error type. typedef robin_hood::unordered_flat_map<StringID, ScriptErrorType> ScriptErrorMap; ///< The type for mapping between error (internal OpenTTD) StringID to the script error type.
typedef std::map<ScriptErrorType, const char *> ScriptErrorMapString; ///< The type for mapping between error type and textual representation. typedef robin_hood::unordered_flat_map<ScriptErrorType, const char *> 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 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. static ScriptErrorMapString error_map_string; ///< The mapping between error type and textual representation.

View File

@@ -25,6 +25,7 @@
#include "../economy_base.h" #include "../economy_base.h"
#include "../event_logs.h" #include "../event_logs.h"
#include "../3rdparty/cpp-btree/btree_map.h" #include "../3rdparty/cpp-btree/btree_map.h"
#include "../3rdparty/robin_hood/robin_hood.h"
#include "../core/format.hpp" #include "../core/format.hpp"
#include "saveload.h" #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 * 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 * b) both next_shared and previous_shared are set for later games
*/ */
std::map<Order*, OrderList*> mapping; robin_hood::unordered_flat_map<Order*, OrderList*> mapping;
for (Vehicle *v : Vehicle::Iterate()) { for (Vehicle *v : Vehicle::Iterate()) {
si_v = v; si_v = v;

View File

@@ -12,7 +12,7 @@
#define TIMER_MANAGER_H #define TIMER_MANAGER_H
#include "../stdafx.h" #include "../stdafx.h"
#include <set> #include "../3rdparty/cpp-btree/btree_set.h"
template <typename TTimerType> template <typename TTimerType>
class BaseTimer; class BaseTimer;
@@ -112,9 +112,9 @@ private:
}; };
/** Singleton list, to store all the active timers. */ /** Singleton list, to store all the active timers. */
static std::set<BaseTimer<TTimerType> *, base_timer_sorter> &GetTimers() static btree::btree_set<BaseTimer<TTimerType> *, base_timer_sorter> &GetTimers()
{ {
static std::set<BaseTimer<TTimerType> *, base_timer_sorter> timers; static btree::btree_set<BaseTimer<TTimerType> *, base_timer_sorter> timers;
return timers; return timers;
} }
}; };