1
0
Fork 0

Codechange: Use AirportSpec::index instead of GetIndex().

GetIndex() used pointer arithmetic to determine the index, which is already known.
pull/12864/head
Peter Nelson 2024-07-17 09:44:09 +01:00
parent 891e53c72e
commit 53c96df94b
No known key found for this signature in database
GPG Key ID: 8EF8F0A467DF75ED
3 changed files with 4 additions and 11 deletions

View File

@ -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;
}
}

View File

@ -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) {

View File

@ -128,13 +128,6 @@ struct AirportSpec : NewGRFSpecBase<AirportClassID> {
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<uint8_t>(std::distance(std::cbegin(specs), this));
}
static const AirportSpec dummy; ///< The dummy airport.
private: