diff --git a/src/cargomonitor.cpp b/src/cargomonitor.cpp index b1d52d6b18..70d6a9c697 100644 --- a/src/cargomonitor.cpp +++ b/src/cargomonitor.cpp @@ -32,12 +32,11 @@ static void ClearCargoMonitoring(CargoMonitorMap &cargo_monitor_map, CompanyID c return; } - CargoMonitorMap::iterator next; - for (CargoMonitorMap::iterator it = cargo_monitor_map.begin(); it != cargo_monitor_map.end(); it = next) { - next = it; - next++; + for (CargoMonitorMap::iterator it = cargo_monitor_map.begin(); it != cargo_monitor_map.end();) { if (DecodeMonitorCompany(it->first) == company) { - cargo_monitor_map.erase(it); + it = cargo_monitor_map.erase(it); + } else { + ++it; } } } diff --git a/src/cargomonitor.h b/src/cargomonitor.h index 061a1821a4..cab26785fd 100644 --- a/src/cargomonitor.h +++ b/src/cargomonitor.h @@ -17,8 +17,7 @@ #include "industry.h" #include "town.h" #include "core/overflowsafe_type.hpp" -#include - +#include "3rdparty/cpp-btree/btree_map.h" struct Station; /** @@ -32,7 +31,7 @@ struct Station; typedef uint32 CargoMonitorID; ///< Type of the cargo monitor number. /** Map type for storing and updating active cargo monitor numbers and their amounts. */ -typedef std::map CargoMonitorMap; +typedef btree::btree_map CargoMonitorMap; extern CargoMonitorMap _cargo_pickups; extern CargoMonitorMap _cargo_deliveries; diff --git a/src/landscape.cpp b/src/landscape.cpp index 17dfca85a0..18efa43c49 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -33,8 +33,8 @@ #include "tunnelbridge_map.h" #include "pathfinder/npf/aystar.h" #include "saveload/saveload.h" +#include "3rdparty/cpp-btree/btree_set.h" #include -#include #include "table/strings.h" #include "table/sprites.h" @@ -1119,7 +1119,7 @@ static bool FlowRiver(TileIndex spring, TileIndex begin) uint height = TileHeight(begin); if (IsWaterTile(begin)) return DistanceManhattan(spring, begin) > _settings_game.game_creation.min_river_length; - std::set marks; + btree::btree_set marks; SET_MARK(begin); /* Breadth first search for the closest tile we can flow down to. */ @@ -1156,7 +1156,7 @@ static bool FlowRiver(TileIndex spring, TileIndex begin) /* Maybe we can make a lake. Find the Nth of the considered tiles. */ TileIndex lakeCenter = 0; int i = RandomRange(count - 1) + 1; - std::set::const_iterator cit = marks.begin(); + btree::btree_set::const_iterator cit = marks.begin(); while (--i) cit++; lakeCenter = *cit; diff --git a/src/linkgraph/mcf.cpp b/src/linkgraph/mcf.cpp index 3a00a2a0e8..2972f4aaf9 100644 --- a/src/linkgraph/mcf.cpp +++ b/src/linkgraph/mcf.cpp @@ -3,11 +3,12 @@ #include "../stdafx.h" #include "../core/math_func.hpp" #include "mcf.h" +#include "../3rdparty/cpp-btree/btree_map.h" #include #include "../safeguards.h" -typedef std::map PathViaMap; +typedef btree::btree_map PathViaMap; /** * This is a wrapper around Tannotation* which also stores a cache of GetAnnotation() and GetNode() diff --git a/src/linkgraph/refresh.h b/src/linkgraph/refresh.h index 0b834a3e54..da15fbbebd 100644 --- a/src/linkgraph/refresh.h +++ b/src/linkgraph/refresh.h @@ -14,9 +14,9 @@ #include "../cargo_type.h" #include "../vehicle_base.h" +#include "../3rdparty/cpp-btree/btree_set.h" #include #include -#include /** * Utility to refresh links a consist will visit. @@ -67,7 +67,7 @@ protected: * Default constructor should not be called but has to be visible for * usage in std::set. */ - Hop() {NOT_REACHED();} + Hop() {} /** * Real constructor, only use this one. @@ -80,7 +80,7 @@ protected: }; typedef std::vector RefitList; - typedef std::set HopSet; + typedef btree::btree_set HopSet; Vehicle *vehicle; ///< Vehicle for which the links should be refreshed. uint capacities[NUM_CARGO]; ///< Current added capacities per cargo ID in the consist. diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 7579636a12..b61db5918e 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -41,7 +41,6 @@ #include "date_func.h" #include "string_func.h" #include "network/network.h" -#include #include "smallmap_gui.h" #include "genworld.h" #include "error.h" @@ -52,6 +51,8 @@ #include "table/strings.h" #include "table/build_industry.h" +#include "3rdparty/cpp-btree/btree_map.h" + #include "safeguards.h" /* TTDPatch extended GRF format codec @@ -90,7 +91,7 @@ private: }; /** Currently referenceable spritesets */ - std::map spritesets[GSF_END]; + btree::btree_map spritesets[GSF_END]; public: /* Global state */ @@ -347,6 +348,7 @@ struct GRFLocation { uint32 grfid; uint32 nfoline; + GRFLocation() { } GRFLocation(uint32 grfid, uint32 nfoline) : grfid(grfid), nfoline(nfoline) { } bool operator<(const GRFLocation &other) const @@ -360,8 +362,8 @@ struct GRFLocation { } }; -static std::map _grm_sprites; -typedef std::map GRFLineToSpriteOverride; +static btree::btree_map _grm_sprites; +typedef btree::btree_map GRFLineToSpriteOverride; static GRFLineToSpriteOverride _grf_line_to_action6_sprite_override; /** @@ -5931,7 +5933,7 @@ static void CfgApply(ByteReader *buf) GRFLineToSpriteOverride::iterator it = _grf_line_to_action6_sprite_override.find(location); if (it != _grf_line_to_action6_sprite_override.end()) { free(preload_sprite); - preload_sprite = _grf_line_to_action6_sprite_override[location]; + preload_sprite = it->second; } else { _grf_line_to_action6_sprite_override[location] = preload_sprite; } @@ -8760,7 +8762,7 @@ static void DecodeSpecialSprite(byte *buf, uint num, GrfLoadingStage stage) FioReadBlock(buf, num); } else { /* Use the preloaded sprite data. */ - buf = _grf_line_to_action6_sprite_override[location]; + buf = it->second; grfmsg(7, "DecodeSpecialSprite: Using preloaded pseudo sprite data"); /* Skip the real (original) content of this action. */ diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 3ec80b6504..f052f8fd13 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -24,6 +24,8 @@ #include "table/strings.h" #include "table/palette_convert.h" +#include "3rdparty/cpp-btree/btree_map.h" + #include "safeguards.h" /* Default of 4MB spritecache */ @@ -476,7 +478,7 @@ static void *ReadSprite(const SpriteCache *sc, SpriteID id, SpriteType sprite_ty /** Map from sprite numbers to position in the GRF file. */ -static std::map _grf_sprite_offsets; +static btree::btree_map _grf_sprite_offsets; /** * Get the file offset for a specific sprite in the sprite section of a GRF. @@ -485,7 +487,8 @@ static std::map _grf_sprite_offsets; */ size_t GetGRFSpriteOffset(uint32 id) { - return _grf_sprite_offsets.find(id) != _grf_sprite_offsets.end() ? _grf_sprite_offsets[id] : SIZE_MAX; + auto iter = _grf_sprite_offsets.find(id); + return iter != _grf_sprite_offsets.end() ? iter->second : SIZE_MAX; } /** diff --git a/src/terraform_cmd.cpp b/src/terraform_cmd.cpp index aad9822822..1e9888e489 100644 --- a/src/terraform_cmd.cpp +++ b/src/terraform_cmd.cpp @@ -21,15 +21,15 @@ #include "table/strings.h" -#include -#include +#include "3rdparty/cpp-btree/btree_set.h" +#include "3rdparty/cpp-btree/btree_map.h" #include "safeguards.h" /** Set of tiles. */ -typedef std::set TileIndexSet; +typedef btree::btree_set TileIndexSet; /** Mapping of tiles to their height. */ -typedef std::map TileIndexToHeightMap; +typedef btree::btree_map TileIndexToHeightMap; /** State of the terraforming. */ struct TerraformerState { diff --git a/src/tracerestrict.h b/src/tracerestrict.h index ab41f3bacb..604269d1e5 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -18,7 +18,7 @@ #include "rail_map.h" #include "tile_type.h" #include "group_type.h" -#include +#include "3rdparty/cpp-btree/btree_map.h" #include struct Train; @@ -50,7 +50,7 @@ struct TraceRestrictMappingItem { : program_id(program_id_) { } }; -typedef std::map TraceRestrictMapping; +typedef btree::btree_map TraceRestrictMapping; /** The actual mapping from TraceRestrictRefId to TraceRestrictProgramID. */ extern TraceRestrictMapping _tracerestrictprogram_mapping; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 9634f04579..e6900e034e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -57,6 +57,7 @@ #include "tbtr_template_vehicle_func.h" #include "string_func.h" #include "scope_info.h" +#include "3rdparty/cpp-btree/btree_set.h" #include "table/strings.h" @@ -75,7 +76,7 @@ uint16 _returned_mail_refit_capacity; ///< Stores the mail capacity after a refi VehiclePool _vehicle_pool("Vehicle"); INSTANTIATE_POOL_METHODS(Vehicle) -static std::set _vehicles_to_pay_repair; +static btree::btree_set _vehicles_to_pay_repair; /** * Determine shared bounds of all sprites.