From 53c96df94bd096aad08a717d246b47135356e738 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Wed, 17 Jul 2024 09:44:09 +0100 Subject: [PATCH] Codechange: Use AirportSpec::index instead of GetIndex(). GetIndex() used pointer arithmetic to determine the index, which is already known. --- src/airport_gui.cpp | 4 ++-- src/newgrf_airport.cpp | 4 ++-- src/newgrf_airport.h | 7 ------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index a09bc82a89..34ef21fe7a 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -64,7 +64,7 @@ static void PlaceAirport(TileIndex tile) { if (_selected_airport_index == -1) return; - uint8_t airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->GetIndex(); + uint8_t airport_type = AirportClass::Get(_selected_airport_class)->GetSpec(_selected_airport_index)->index; uint8_t layout = _selected_airport_layout; bool adjacent = _ctrl_pressed; @@ -551,7 +551,7 @@ public: if (as->IsAvailable()) { _selected_airport_class = cls.Index(); this->vscroll->SetCount(cls.GetSpecCount()); - this->SelectOtherAirport(as->GetIndex()); + this->SelectOtherAirport(as->index); return; } } diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index 1471f417e2..c1091d8990 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -251,7 +251,7 @@ AirportResolverObject::AirportResolverObject(TileIndex tile, Station *st, uint8_ SpriteID GetCustomAirportSprite(const AirportSpec *as, uint8_t layout) { - AirportResolverObject object(INVALID_TILE, nullptr, as->GetIndex(), layout); + AirportResolverObject object(INVALID_TILE, nullptr, as->index, layout); const SpriteGroup *group = object.Resolve(); if (group == nullptr) return as->preview_sprite; @@ -273,7 +273,7 @@ uint16_t GetAirportCallback(CallbackID callback, uint32_t param1, uint32_t param */ StringID GetAirportTextCallback(const AirportSpec *as, uint8_t layout, uint16_t callback) { - AirportResolverObject object(INVALID_TILE, nullptr, as->GetIndex(), layout, (CallbackID)callback); + AirportResolverObject object(INVALID_TILE, nullptr, as->index, layout, (CallbackID)callback); uint16_t cb_res = object.ResolveCallback(); if (cb_res == CALLBACK_FAILED || cb_res == 0x400) return STR_UNDEFINED; if (cb_res > 0x400) { diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h index 5ac58bc72d..a172ae81d0 100644 --- a/src/newgrf_airport.h +++ b/src/newgrf_airport.h @@ -128,13 +128,6 @@ struct AirportSpec : NewGRFSpecBase { static void ResetAirports(); - /** Get the index of this spec. */ - uint8_t GetIndex() const - { - assert(this >= std::begin(specs) && this < std::end(specs)); - return static_cast(std::distance(std::cbegin(specs), this)); - } - static const AirportSpec dummy; ///< The dummy airport. private: