aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-11-21 18:21:45 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-11-21 18:21:45 +0000
commit5eebff4026a0a5146d5866e372c9f5c002aa31c9 (patch)
tree814f2a574c956f45defad958e3c1262796e7c452
parent0d407815c20ed74cd3d5cb3b663d6c0ab007fc86 (diff)
downloadpaludis-5eebff4026a0a5146d5866e372c9f5c002aa31c9.tar.gz
paludis-5eebff4026a0a5146d5866e372c9f5c002aa31c9.tar.xz
Don't bother keeping duplicate require_ifs
-rw-r--r--paludis/resolver/job_requirements-fwd.hh3
-rw-r--r--paludis/resolver/job_requirements.cc44
-rw-r--r--paludis/resolver/orderer.cc12
3 files changed, 56 insertions, 3 deletions
diff --git a/paludis/resolver/job_requirements-fwd.hh b/paludis/resolver/job_requirements-fwd.hh
index 4c974d8..dec1677 100644
--- a/paludis/resolver/job_requirements-fwd.hh
+++ b/paludis/resolver/job_requirements-fwd.hh
@@ -24,6 +24,7 @@
#include <paludis/util/options-fwd.hh>
#include <paludis/util/attributes.hh>
#include <iosfwd>
+#include <memory>
namespace paludis
{
@@ -35,6 +36,8 @@ namespace paludis
struct JobRequirement;
typedef Sequence<JobRequirement> JobRequirements;
+
+ const std::shared_ptr<JobRequirements> minimise_requirements(const std::shared_ptr<const JobRequirements> &);
}
}
diff --git a/paludis/resolver/job_requirements.cc b/paludis/resolver/job_requirements.cc
index 7fda1d0..7098f4d 100644
--- a/paludis/resolver/job_requirements.cc
+++ b/paludis/resolver/job_requirements.cc
@@ -23,9 +23,11 @@
#include <paludis/util/wrapped_forward_iterator-impl.hh>
#include <paludis/util/sequence-impl.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/enum_iterator.hh>
#include <paludis/serialise-impl.hh>
#include <istream>
#include <ostream>
+#include <set>
using namespace paludis;
using namespace paludis::resolver;
@@ -51,6 +53,48 @@ JobRequirement::serialise(Serialiser & s) const
;
}
+namespace
+{
+ struct JobRequirementComparator
+ {
+ bool operator() (const JobRequirement & a, const JobRequirement & b)
+ {
+ if (a.job_number() < b.job_number())
+ return true;
+ if (a.job_number() > b.job_number())
+ return false;
+
+ for (EnumIterator<JobRequirementIf> t, t_end(last_jri) ; t != t_end ; ++t)
+ {
+ if (a.required_if()[*t] < b.required_if()[*t])
+ return true;
+ if (a.required_if()[*t] > b.required_if()[*t])
+ return false;
+ }
+
+ return false;
+ }
+ };
+}
+
+const std::shared_ptr<JobRequirements>
+paludis::resolver::minimise_requirements(const std::shared_ptr<const JobRequirements> & reqs)
+{
+ const std::shared_ptr<JobRequirements> result(std::make_shared<JobRequirements>());
+ std::set<JobRequirement, JobRequirementComparator> duplicates;
+
+ for (auto r(reqs->begin()), r_end(reqs->end()) ;
+ r != r_end ; ++r)
+ {
+ if (! duplicates.insert(*r).second)
+ continue;
+
+ result->push_back(*r);
+ }
+
+ return result;
+}
+
template class Sequence<JobRequirement>;
template class WrappedForwardIterator<Sequence<JobRequirement>::ConstIteratorTag, const JobRequirement>;
diff --git a/paludis/resolver/orderer.cc b/paludis/resolver/orderer.cc
index f475149..6879807 100644
--- a/paludis/resolver/orderer.cc
+++ b/paludis/resolver/orderer.cc
@@ -843,7 +843,7 @@ namespace
changes_to_make_decision.destination()->repository(),
changes_to_make_decision.resolvent().destination_type()));
- const std::shared_ptr<JobRequirements> requirements(std::make_shared<JobRequirements>());
+ std::shared_ptr<JobRequirements> requirements(std::make_shared<JobRequirements>());
requirements->push_back(make_named_values<JobRequirement>(
n::job_number() = fetch_job_n->second,
n::required_if() = JobRequirementIfs() + jri_require_for_satisfied + jri_require_for_independent
@@ -862,6 +862,8 @@ namespace
recursed
);
+ requirements = minimise_requirements(requirements);
+
const std::shared_ptr<Sequence<PackageDepSpec> > replacing(std::make_shared<Sequence<PackageDepSpec>>());
for (PackageIDSequence::ConstIterator i(changes_to_make_decision.destination()->replacing()->begin()),
i_end(changes_to_make_decision.destination()->replacing()->end()) ;
@@ -882,7 +884,7 @@ namespace
case nir_fetched:
{
- const std::shared_ptr<JobRequirements> requirements(std::make_shared<JobRequirements>());
+ std::shared_ptr<JobRequirements> requirements(std::make_shared<JobRequirements>());
RecursedRequirements recursed;
populate_requirements(
@@ -896,6 +898,8 @@ namespace
recursed
);
+ requirements = minimise_requirements(requirements);
+
JobNumber fetch_job_n(resolved->job_lists()->execute_job_list()->append(std::make_shared<FetchJob>(
requirements,
make_origin_spec(changes_to_make_decision))));
@@ -918,7 +922,7 @@ namespace
i != i_end ; ++i)
removing->push_back((*i)->uniquely_identifying_spec());
- const std::shared_ptr<JobRequirements> requirements(std::make_shared<JobRequirements>());
+ std::shared_ptr<JobRequirements> requirements(std::make_shared<JobRequirements>());
RecursedRequirements recursed;
populate_requirements(
resolved->nag(),
@@ -931,6 +935,8 @@ namespace
recursed
);
+ requirements = minimise_requirements(requirements);
+
JobNumber uninstall_job_n(resolved->job_lists()->execute_job_list()->append(std::make_shared<UninstallJob>(
requirements,
removing