Codechange: Convert StationList from SmallVector to std::set.

This commit is contained in:
peter1138 2019-02-24 18:52:15 +00:00 committed by PeterN
parent 46aca9377b
commit ed6084523d
6 changed files with 17 additions and 11 deletions

View File

@ -2432,7 +2432,7 @@ static int WhoCanServiceIndustry(Industry *ind)
StationList stations;
FindStationsAroundTiles(ind->location, &stations);
if (stations.Length() == 0) return 0; // No stations found at all => nobody services
if (stations.size() == 0) return 0; // No stations found at all => nobody services
const Vehicle *v;
int result = 0;
@ -2468,7 +2468,7 @@ static int WhoCanServiceIndustry(Industry *ind)
/* Same cargo produced by industry is dropped here => not serviced by vehicle v */
if ((o->GetUnloadType() & OUFB_UNLOAD) && !c_accepts) break;
if (stations.Contains(st)) {
if (stations.find(st) != stations.end()) {
if (v->owner == _local_company) return 2; // Company services industry
result = 1; // Competitor services industry
}

View File

@ -350,8 +350,7 @@ static uint32 GetDistanceFromNearbyHouse(uint8 parameter, TileIndex tile, HouseI
/* Collect acceptance stats. */
uint32 res = 0;
for (Station * const * st_iter = sl->Begin(); st_iter != sl->End(); st_iter++) {
const Station *st = *st_iter;
for (Station *st : *sl) {
if (HasBit(st->goods[cid].status, GoodsEntry::GES_EVER_ACCEPTED)) SetBit(res, 0);
if (HasBit(st->goods[cid].status, GoodsEntry::GES_LAST_MONTH)) SetBit(res, 1);
if (HasBit(st->goods[cid].status, GoodsEntry::GES_CURRENT_MONTH)) SetBit(res, 2);

View File

@ -134,7 +134,7 @@
Industry *ind = ::Industry::Get(industry_id);
StationList stations;
::FindStationsAroundTiles(ind->location, &stations);
return (int32)stations.Length();
return (int32)stations.size();
}
/* static */ int32 ScriptIndustry::GetDistanceManhattanToTile(IndustryID industry_id, TileIndex tile)

View File

@ -571,3 +571,8 @@ Money AirportMaintenanceCost(Owner owner)
/* 3 bits fraction for the maintenance cost factor. */
return total_cost >> 3;
}
bool StationCompare::operator() (const Station *lhs, const Station *rhs) const
{
return lhs->index < rhs->index;
}

View File

@ -3839,7 +3839,7 @@ void FindStationsAroundTiles(const TileArea &location, StationList *stations)
/* Insert the station in the set. This will fail if it has
* already been added.
*/
stations->Include(st);
stations->insert(st);
}
}
}
@ -3867,9 +3867,7 @@ uint MoveGoodsToStation(CargoID type, uint amount, SourceType source_type, Sourc
uint best_rating1 = 0; // rating of st1
uint best_rating2 = 0; // rating of st2
for (Station * const *st_iter = all_stations->Begin(); st_iter != all_stations->End(); ++st_iter) {
Station *st = *st_iter;
for (Station *st : *all_stations) {
/* Is the station reserved exclusively for somebody else? */
if (st->owner != OWNER_NONE && st->town->exclusive_counter > 0 && st->town->exclusivity != st->owner) continue;

View File

@ -12,9 +12,9 @@
#ifndef STATION_TYPE_H
#define STATION_TYPE_H
#include "core/smallvec_type.hpp"
#include "core/smallstack_type.hpp"
#include "tilearea_type.h"
#include <set>
typedef uint16 StationID;
typedef uint16 RoadStopID;
@ -90,8 +90,12 @@ enum CatchmentArea {
static const uint MAX_LENGTH_STATION_NAME_CHARS = 32; ///< The maximum length of a station name in characters including '\0'
struct StationCompare {
bool operator() (const Station *lhs, const Station *rhs) const;
};
/** List of stations */
typedef SmallVector<Station *, 2> StationList;
typedef std::set<Station *, StationCompare> StationList;
/**
* Structure contains cached list of stations nearby. The list