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

30 lines
1.4 KiB
Diff

# UNDF: UNDF-2026-000000997
--- a/universe/Tech.cpp
+++ b/universe/Tech.cpp
@@ -593,6 +593,7 @@ std::string TechManager::FindFirstDependencyCycle() const {
std::vector<const Tech*> stack;
stack.reserve(m_techs.size());
+ std::unordered_set<const Tech*> stack_set;
stack.push_back(&tech);
while (!stack.empty()) {
// Examine the tech on top of the stack. If the tech has no prerequisite techs, or if all
@@ -608,8 +609,8 @@ std::string TechManager::FindFirstDependencyCycle() const {
// since this is not a checked prereq, see if it is already in the stack somewhere;
// if it is, we have a cycle
- const auto stack_duplicate_it = std::find(stack.rbegin(), stack.rend(), prereq_tech);
- if (stack_duplicate_it == stack.rend()) {
+ if (!stack_set.contains(prereq_tech)) {
// OK! no cycle, move to next prereq
+ stack_set.insert(prereq_tech);
stack.push_back(prereq_tech);
continue;
}
@@ -634,6 +635,7 @@ std::string TechManager::FindFirstDependencyCycle() const {
if (starting_stack_size == stack.size()) {
stack.pop_back();
+ stack_set.erase(current_tech);
checked_techs.insert(current_tech);
}
}