diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-20 12:21:42 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-03-06 20:06:40 +0100 |
| commit | 7194a6b39c2aa6f1006630975a1bf4ffc3c9daf2 (patch) | |
| tree | 6da02dee8aae5f908d84de6e67b2d4ea791310f2 /apt-pkg/solver3.cc | |
| parent | 56c14eab8f399497295bb74d551dc49a4a763486 (diff) | |
solver3: refactor: Return inserted Clause in AddWork()
This avoids relying on the inserted clause being at the back
of the clauses vector.
Diffstat (limited to 'apt-pkg/solver3.cc')
| -rw-r--r-- | apt-pkg/solver3.cc | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/apt-pkg/solver3.cc b/apt-pkg/solver3.cc index c1a1098b5..5469a1881 100644 --- a/apt-pkg/solver3.cc +++ b/apt-pkg/solver3.cc @@ -444,13 +444,14 @@ bool APT::Solver::Propagate() return true; } -void APT::Solver::RegisterClause(Clause &&clause) +const APT::Solver::Clause *APT::Solver::RegisterClause(Clause &&clause) { auto &clauses = (*this)[clause.reason].clauses; clauses.push_back(std::make_unique<Clause>(std::move(clause))); auto const &inserted = clauses.back(); for (auto var : inserted->solutions) (*this)[var].rclauses.push_back(inserted.get()); + return inserted.get(); } void APT::Solver::Discover(Var var) @@ -931,8 +932,8 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache) { Clause w{Var(), Group, isOptional}; w.solutions.push_back(Var(P)); - RegisterClause(std::move(w)); - if (not AddWork(Work{rootState->clauses.back().get(), depth()})) + auto insertedW = RegisterClause(std::move(w)); + if (not AddWork(Work{insertedW, depth()})) return false; // Given A->A2|A1, B->B1|B2; Bn->An, if we select `not A1`, we @@ -944,8 +945,8 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache) for (auto V = P.VersionList(); not V.end(); ++V) shortcircuit.solutions.push_back(Var(V)); std::stable_sort(shortcircuit.solutions.begin(), shortcircuit.solutions.end(), CompareProviders3{cache, policy, P, *this}); - RegisterClause(std::move(shortcircuit)); - if (not AddWork(Work{rootState->clauses.back().get(), depth()})) + auto insertedShort = RegisterClause(std::move(shortcircuit)); + if (not AddWork(Work{insertedShort, depth()})) return false; // Discovery here is needed so the shortcircuit clause can actually become unit. @@ -963,8 +964,8 @@ bool APT::Solver::FromDepCache(pkgDepCache &depcache) std::stable_sort(w.solutions.begin(), w.solutions.end(), CompareProviders3{cache, policy, P, *this}); if (unlikely(debug >= 1)) std::cerr << "Install essential package " << P << std::endl; - RegisterClause(std::move(w)); - if (not AddWork(Work{rootState->clauses.back().get(), depth()})) + auto inserted = RegisterClause(std::move(w)); + if (not AddWork(Work{inserted, depth()})) return false; } } |
