From 52bada216cb272153f7010ce249bdadccd4b2135 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sun, 9 Mar 2025 05:48:22 +0000 Subject: [PATCH] Codechange: Use std::array for vehicle hashes. This allows initialisation without memset. --- src/vehicle.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2648a2efb8..c6d9ff973e 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -381,7 +381,7 @@ const int TOTAL_HASH_MASK = TOTAL_HASH_SIZE - 1; * Profiling results show that 0 is fastest. */ const int HASH_RES = 0; -static Vehicle *_vehicle_tile_hash[TOTAL_HASH_SIZE]; +static std::array _vehicle_tile_hash{}; static Vehicle *VehicleFromTileHash(int xl, int yl, int xu, int yu, void *data, VehicleFromPosProc *proc, bool find_first) { @@ -646,7 +646,7 @@ static void UpdateVehicleTileHash(Vehicle *v, bool remove) v->hash_tile_current = new_hash; } -static Vehicle *_vehicle_viewport_hash[1 << (GEN_HASHX_BITS + GEN_HASHY_BITS)]; +static std::array _vehicle_viewport_hash{}; static void UpdateVehicleViewportHash(Vehicle *v, int x, int y, int old_x, int old_y) { @@ -675,8 +675,8 @@ static void UpdateVehicleViewportHash(Vehicle *v, int x, int y, int old_x, int o void ResetVehicleHash() { for (Vehicle *v : Vehicle::Iterate()) { v->hash_tile_current = nullptr; } - memset(_vehicle_viewport_hash, 0, sizeof(_vehicle_viewport_hash)); - memset(_vehicle_tile_hash, 0, sizeof(_vehicle_tile_hash)); + _vehicle_viewport_hash = {}; + _vehicle_tile_hash = {}; } void ResetVehicleColourMap()