Slightly speed up unordered iteration of FlowStatMap

pull/642/head
Jonathan G Rennison 5 months ago
parent 4458d3b61c
commit 81c2c4a881

@ -22,6 +22,7 @@
#include "bitmap_type.h"
#include "core/alloc_type.hpp"
#include "core/endian_type.hpp"
#include "core/span_type.hpp"
#include "strings_type.h"
#include <map>
#include <vector>
@ -504,6 +505,11 @@ public:
}
void SortStorage();
span<const FlowStat> IterateUnordered() const
{
return span<const FlowStat>(this->flows_storage.data(), this->flows_storage.size());
}
};
struct GoodsEntryData : ZeroedMemoryAllocator {

@ -5629,7 +5629,7 @@ void FlowStatMap::RestrictFlows(StationID via)
uint FlowStatMap::GetFlow() const
{
uint ret = 0;
for (const FlowStat &it : *this) {
for (const FlowStat &it : this->IterateUnordered()) {
if (it.IsInvalid()) continue;
ret += (it.end() - 1)->first;
}
@ -5644,7 +5644,7 @@ uint FlowStatMap::GetFlow() const
uint FlowStatMap::GetFlowVia(StationID via) const
{
uint ret = 0;
for (const FlowStat &it : *this) {
for (const FlowStat &it : this->IterateUnordered()) {
if (it.IsInvalid()) continue;
ret += it.GetShare(via);
}

@ -2109,7 +2109,7 @@ class NIHStationStruct : public NIHelper {
}
if (ge->data != nullptr && ge->data->flows.size() > 0) {
size_t total_shares = 0;
for (const FlowStat &fs : ge->data->flows) {
for (const FlowStat &fs : ge->data->flows.IterateUnordered()) {
total_shares += fs.size();
}
seprintf(buffer, lastof(buffer), " Flows: %u, total shares: %u", (uint)ge->data->flows.size(), (uint)total_shares);

Loading…
Cancel
Save