Move StationCargoList and FlowStatMap out of GoodsEntry struct
Move them into a new GoodsEntryData struct referenced using a std::unique_ptr from GoodsEntry. The unique_ptr may be nullptr if the cargo list and flow stat map are both empty (this is the case for unused cargoes). This reduces GoodsEntry from 128 to 24 bytes, and Station from 8680 to 2024 bytes, (on Linux x86_64).
This commit is contained in:
@@ -58,7 +58,10 @@ template<bool Tfrom, bool Tvia>
|
||||
return -1;
|
||||
}
|
||||
|
||||
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
|
||||
const GoodsEntry &ge = ::Station::Get(station_id)->goods[cargo_id];
|
||||
if (ge.data == nullptr) return 0;
|
||||
|
||||
const StationCargoList &cargo_list = ge.data->cargo;
|
||||
if (!Tfrom && !Tvia) return cargo_list.TotalCount();
|
||||
|
||||
uint16 cargo_count = 0;
|
||||
@@ -106,7 +109,10 @@ template<bool Tfrom, bool Tvia>
|
||||
return -1;
|
||||
}
|
||||
|
||||
const FlowStatMap &flows = ::Station::Get(station_id)->goods[cargo_id].flows;
|
||||
const GoodsEntry &ge = ::Station::Get(station_id)->goods[cargo_id];
|
||||
if (ge.data == nullptr) return 0;
|
||||
|
||||
const FlowStatMap &flows = ge.data->flows;
|
||||
if (Tfrom) {
|
||||
return Tvia ? flows.GetFlowFromVia(from_station_id, via_station_id) :
|
||||
flows.GetFlowFrom(from_station_id);
|
||||
|
Reference in New Issue
Block a user