java-topology/defects/pioneer-0002/patch/pioneer-0002.patch

41 lines
1.2 KiB
Diff

# UNDF: UNDF-2026-000000985
--- a/src/galaxy/Factions.h
+++ b/src/galaxy/Factions.h
@@ -14,6 +14,7 @@
#include <map>
#include <utility>
#include <vector>
+#include <set>
class Galaxy;
class CustomSystem;
@@ -52,8 +53,13 @@ public:
typedef std::vector<SystemPath> ClaimList;
ClaimList m_ownedsystemlist;
- void PushClaim(SystemPath path) { m_ownedsystemlist.push_back(path); }
+ void PushClaim(SystemPath path) {
+ m_ownedsystemlist.push_back(path);
+ m_claimedPathSet.insert(path);
+ }
bool IsClaimed(SystemPath) const;
+private:
+ std::set<SystemPath> m_claimedPathSet; // O(log C) lookup instead of O(C) linear scan
--- a/src/galaxy/Factions.cpp
+++ b/src/galaxy/Factions.cpp
@@ -625,13 +625,11 @@ bool Faction::IsClaimed(SystemPath path) const
{
// check the factions list of claimed systems/sectors, if there is one
SystemPath sector = path;
sector.systemIndex = -99;
- for (auto clam = m_ownedsystemlist.begin(); clam != m_ownedsystemlist.end(); clam++) {
- if (*clam == sector || *clam == path)
- return true;
- }
- return false;
+ // O(log C) set lookup instead of O(C) linear scan per system per faction
+ return m_claimedPathSet.count(sector) > 0 ||
+ m_claimedPathSet.count(path) > 0;
}