diff options
author | 2011-03-11 21:49:24 +0000 | |
---|---|---|
committer | 2011-03-11 21:49:24 +0000 | |
commit | 5bc0738f9d8bf4085952e05961ff9380fa36e0c9 (patch) | |
tree | 4983a33ece2a522b93bd7b62cf60cdd27d1ab503 | |
parent | 75a85b781c6e97e7c5df24a316b385a3aae76423 (diff) | |
download | paludis-5bc0738f9d8bf4085952e05961ff9380fa36e0c9.tar.gz paludis-5bc0738f9d8bf4085952e05961ff9380fa36e0c9.tar.xz |
Pool labels classifications
-rw-r--r-- | paludis/resolver/labels_classifier.cc | 236 | ||||
-rw-r--r-- | paludis/resolver/labels_classifier.hh | 61 | ||||
-rw-r--r-- | paludis/resolver/orderer.cc | 20 | ||||
-rw-r--r-- | paludis/resolver/sanitised_dependencies.cc | 8 |
4 files changed, 206 insertions, 119 deletions
diff --git a/paludis/resolver/labels_classifier.cc b/paludis/resolver/labels_classifier.cc index 3606c7196..5497b8bd9 100644 --- a/paludis/resolver/labels_classifier.cc +++ b/paludis/resolver/labels_classifier.cc @@ -23,6 +23,8 @@ #include <paludis/util/accept_visitor.hh> #include <paludis/util/stringify.hh> #include <paludis/util/pimp-impl.hh> +#include <paludis/util/pool-impl.hh> +#include <paludis/util/singleton-impl.hh> #include <paludis/dep_label.hh> #include <paludis/serialise-impl.hh> #include <algorithm> @@ -33,142 +35,201 @@ using namespace paludis::resolver; namespace paludis { template <> - struct Imp<LabelsClassifier> + struct Imp<LabelsClassifierBuilder> { const Environment * const env; const std::shared_ptr<const PackageID> package_id; + bool any_enabled; + + bool includes_buildish; + bool includes_compile_against; + bool includes_fetch; + bool includes_non_post_runish; + bool includes_non_test_buildish; + bool includes_post; + bool includes_postish; + + bool is_recommendation; + bool is_requirement; + bool is_suggestion; + Imp(const Environment * const e, const std::shared_ptr<const PackageID> & i) : env(e), - package_id(i) + package_id(i), + any_enabled(false), + includes_buildish(false), + includes_compile_against(false), + includes_fetch(false), + includes_non_post_runish(false), + includes_non_test_buildish(false), + includes_post(false), + includes_postish(false), + is_recommendation(false), + is_requirement(false), + is_suggestion(false) { } }; } -LabelsClassifier::LabelsClassifier(const Environment * const env, const std::shared_ptr<const PackageID> & id) : - _imp(env, id), - any_enabled(false), - includes_buildish(false), - includes_compile_against(false), - includes_fetch(false), - includes_non_post_runish(false), - includes_non_test_buildish(false), - includes_post(false), - includes_postish(false), - is_recommendation(false), - is_requirement(false), - is_suggestion(false) +LabelsClassifierBuilder::LabelsClassifierBuilder(const Environment * const env, const std::shared_ptr<const PackageID> & id) : + _imp(env, id) { } -LabelsClassifier::~LabelsClassifier() = default; +LabelsClassifierBuilder::~LabelsClassifierBuilder() = default; void -LabelsClassifier::visit(const DependenciesBuildLabel & l) +LabelsClassifierBuilder::visit(const DependenciesBuildLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_buildish = true; - includes_non_test_buildish = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_buildish = true; + _imp->includes_non_test_buildish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesTestLabel & l) +LabelsClassifierBuilder::visit(const DependenciesTestLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_buildish = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_buildish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesFetchLabel & l) +LabelsClassifierBuilder::visit(const DependenciesFetchLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_buildish = true; - includes_non_test_buildish = true; - includes_fetch = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_buildish = true; + _imp->includes_non_test_buildish = true; + _imp->includes_fetch = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesRunLabel & l) +LabelsClassifierBuilder::visit(const DependenciesRunLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_non_post_runish = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_non_post_runish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesPostLabel & l) +LabelsClassifierBuilder::visit(const DependenciesPostLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_postish = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_postish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesInstallLabel & l) +LabelsClassifierBuilder::visit(const DependenciesInstallLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_buildish = true; - includes_non_test_buildish = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_buildish = true; + _imp->includes_non_test_buildish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesCompileAgainstLabel & l) +LabelsClassifierBuilder::visit(const DependenciesCompileAgainstLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_requirement = true; - includes_non_post_runish = true; - includes_buildish = true; - includes_non_test_buildish = true; - any_enabled = true; + _imp->is_requirement = true; + _imp->includes_non_post_runish = true; + _imp->includes_buildish = true; + _imp->includes_non_test_buildish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesRecommendationLabel & l) +LabelsClassifierBuilder::visit(const DependenciesRecommendationLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_recommendation = true; - includes_postish = true; - any_enabled = true; + _imp->is_recommendation = true; + _imp->includes_postish = true; + _imp->any_enabled = true; } } void -LabelsClassifier::visit(const DependenciesSuggestionLabel & l) +LabelsClassifierBuilder::visit(const DependenciesSuggestionLabel & l) { if (l.enabled(_imp->env, _imp->package_id)) { - is_suggestion = true; - includes_postish = true; - any_enabled = true; + _imp->is_suggestion = true; + _imp->includes_postish = true; + _imp->any_enabled = true; } } +const std::shared_ptr<const LabelsClassifier> +LabelsClassifierBuilder::create() const +{ + return Pool<LabelsClassifier>::get_instance()->create( + _imp->any_enabled, + _imp->includes_buildish, + _imp->includes_compile_against, + _imp->includes_fetch, + _imp->includes_non_post_runish, + _imp->includes_non_test_buildish, + _imp->includes_post, + _imp->includes_postish, + _imp->is_recommendation, + _imp->is_requirement, + _imp->is_suggestion + ); +} + +LabelsClassifier::LabelsClassifier( + bool any_enabled_v, + bool includes_buildish_v, + bool includes_compile_against_v, + bool includes_fetch_v, + bool includes_non_post_runish_v, + bool includes_non_test_buildish_v, + bool includes_post_v, + bool includes_postish_v, + bool is_recommendation_v, + bool is_requirement_v, + bool is_suggestion_v + ) : + any_enabled(any_enabled_v), + includes_buildish(includes_buildish_v), + includes_compile_against(includes_compile_against_v), + includes_fetch(includes_fetch_v), + includes_non_post_runish(includes_non_post_runish_v), + includes_non_test_buildish(includes_non_test_buildish_v), + includes_post(includes_post_v), + includes_postish(includes_postish_v), + is_recommendation(is_recommendation_v), + is_requirement(is_requirement_v), + is_suggestion(is_suggestion_v) +{ +} + void LabelsClassifier::serialise(Serialiser & s) const { @@ -187,25 +248,24 @@ LabelsClassifier::serialise(Serialiser & s) const ; } -const std::shared_ptr<LabelsClassifier> +const std::shared_ptr<const LabelsClassifier> LabelsClassifier::deserialise( Deserialisation & d) { Deserialisator v(d, "LabelsClassifier"); - auto result(std::make_shared<LabelsClassifier>(static_cast<const Environment *>(0), std::shared_ptr<const PackageID>())); - result->any_enabled = v.member<bool>("any_enabled"); - result->includes_buildish = v.member<bool>("includes_buildish"); - result->includes_compile_against = v.member<bool>("includes_compile_against"); - result->includes_fetch = v.member<bool>("includes_fetch"); - result->includes_non_post_runish = v.member<bool>("includes_non_post_runish"); - result->includes_non_test_buildish = v.member<bool>("includes_non_test_buildish"); - result->includes_post = v.member<bool>("includes_post"); - result->includes_postish = v.member<bool>("includes_postish"); - result->is_recommendation = v.member<bool>("is_recommendation"); - result->is_requirement = v.member<bool>("is_requirement"); - result->is_suggestion = v.member<bool>("is_suggestion"); - - return result; + return Pool<LabelsClassifier>::get_instance()->create( + v.member<bool>("any_enabled"), + v.member<bool>("includes_buildish"), + v.member<bool>("includes_compile_against"), + v.member<bool>("includes_fetch"), + v.member<bool>("includes_non_post_runish"), + v.member<bool>("includes_non_test_buildish"), + v.member<bool>("includes_post"), + v.member<bool>("includes_postish"), + v.member<bool>("is_recommendation"), + v.member<bool>("is_requirement"), + v.member<bool>("is_suggestion") + ); } bool @@ -214,11 +274,12 @@ paludis::resolver::is_suggestion(const Environment * const env, const std::share if (dep.active_dependency_labels()->empty()) return false; - LabelsClassifier v(env, id); + LabelsClassifierBuilder v(env, id); std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()), indirect_iterator(dep.active_dependency_labels()->end()), accept_visitor(v)); - return v.is_suggestion && (! v.is_recommendation) && (! v.is_requirement); + auto c(v.create()); + return c->is_suggestion && (! c->is_recommendation) && (! c->is_requirement); } bool @@ -227,11 +288,12 @@ paludis::resolver::is_recommendation(const Environment * const env, const std::s if (dep.active_dependency_labels()->empty()) return false; - LabelsClassifier v(env, id); + LabelsClassifierBuilder v(env, id); std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()), indirect_iterator(dep.active_dependency_labels()->end()), accept_visitor(v)); - return v.is_recommendation && (! v.is_requirement); + auto c(v.create()); + return c->is_recommendation && (! c->is_requirement); } bool @@ -240,11 +302,12 @@ paludis::resolver::is_just_build_dep(const Environment * const env, const std::s if (dep.active_dependency_labels()->empty()) throw InternalError(PALUDIS_HERE, "not implemented"); - LabelsClassifier v(env, id); + LabelsClassifierBuilder v(env, id); std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()), indirect_iterator(dep.active_dependency_labels()->end()), accept_visitor(v)); - return v.includes_buildish && ! v.includes_non_post_runish && ! v.includes_postish; + auto c(v.create()); + return c->includes_buildish && ! c->includes_non_post_runish && ! c->includes_postish; } bool @@ -253,11 +316,12 @@ paludis::resolver::is_compiled_against_dep(const Environment * const env, const if (dep.active_dependency_labels()->empty()) throw InternalError(PALUDIS_HERE, "not implemented"); - LabelsClassifier v(env, id); + LabelsClassifierBuilder v(env, id); std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()), indirect_iterator(dep.active_dependency_labels()->end()), accept_visitor(v)); - return v.includes_compile_against; + auto c(v.create()); + return c->includes_compile_against; } bool @@ -266,11 +330,12 @@ paludis::resolver::is_enabled_dep(const Environment * const env, const std::shar if (dep.active_dependency_labels()->empty()) throw InternalError(PALUDIS_HERE, "not implemented"); - LabelsClassifier v(env, id); + LabelsClassifierBuilder v(env, id); std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()), indirect_iterator(dep.active_dependency_labels()->end()), accept_visitor(v)); - return v.any_enabled; + auto c(v.create()); + return c->any_enabled; } bool @@ -279,10 +344,11 @@ paludis::resolver::is_run_or_post_dep(const Environment * const env, const std:: if (dep.active_dependency_labels()->empty()) throw InternalError(PALUDIS_HERE, "not implemented"); - LabelsClassifier v(env, id); + LabelsClassifierBuilder v(env, id); std::for_each(indirect_iterator(dep.active_dependency_labels()->begin()), indirect_iterator(dep.active_dependency_labels()->end()), accept_visitor(v)); - return v.includes_non_post_runish || v.includes_postish; + auto c(v.create()); + return c->includes_non_post_runish || c->includes_postish; } diff --git a/paludis/resolver/labels_classifier.hh b/paludis/resolver/labels_classifier.hh index 797b4d621..75c1f47d4 100644 --- a/paludis/resolver/labels_classifier.hh +++ b/paludis/resolver/labels_classifier.hh @@ -29,28 +29,50 @@ namespace paludis { namespace resolver { - class LabelsClassifier + struct LabelsClassifier { - private: - Pimp<LabelsClassifier> _imp; + LabelsClassifier( + bool any_enabled, + bool includes_buildish, + bool includes_compile_against, + bool includes_fetch, + bool includes_non_post_runish, + bool includes_non_test_buildish, + bool includes_post, + bool includes_postish, + bool is_recommendation, + bool is_requirement, + bool is_suggestion + ); - public: - LabelsClassifier(const Environment * const, const std::shared_ptr<const PackageID> &); - ~LabelsClassifier(); + bool any_enabled; + + bool includes_buildish; + bool includes_compile_against; + bool includes_fetch; + bool includes_non_post_runish; + bool includes_non_test_buildish; + bool includes_post; + bool includes_postish; + + bool is_recommendation; + bool is_requirement; + bool is_suggestion; + + void serialise(Serialiser &) const; - bool any_enabled; + static const std::shared_ptr<const LabelsClassifier> deserialise( + Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result)); + }; - bool includes_buildish; - bool includes_compile_against; - bool includes_fetch; - bool includes_non_post_runish; - bool includes_non_test_buildish; - bool includes_post; - bool includes_postish; + class LabelsClassifierBuilder + { + private: + Pimp<LabelsClassifierBuilder> _imp; - bool is_recommendation; - bool is_requirement; - bool is_suggestion; + public: + LabelsClassifierBuilder(const Environment * const, const std::shared_ptr<const PackageID> &); + ~LabelsClassifierBuilder(); void visit(const DependenciesBuildLabel &); void visit(const DependenciesCompileAgainstLabel &); @@ -62,10 +84,7 @@ namespace paludis void visit(const DependenciesSuggestionLabel &); void visit(const DependenciesTestLabel &); - void serialise(Serialiser &) const; - - static const std::shared_ptr<LabelsClassifier> deserialise( - Deserialisation & d) PALUDIS_ATTRIBUTE((warn_unused_result)); + const std::shared_ptr<const LabelsClassifier> create() const PALUDIS_ATTRIBUTE((warn_unused_result)); }; } } diff --git a/paludis/resolver/orderer.cc b/paludis/resolver/orderer.cc index 1b1df0e2f..59ef7b834 100644 --- a/paludis/resolver/orderer.cc +++ b/paludis/resolver/orderer.cc @@ -254,13 +254,15 @@ namespace return; /* what sort of dep are we? */ - LabelsClassifier classifier(env, r.from_id()); + LabelsClassifierBuilder classifier_builder(env, r.from_id()); for (DependenciesLabelSequence::ConstIterator l(r.sanitised_dependency().active_dependency_labels()->begin()), l_end(r.sanitised_dependency().active_dependency_labels()->end()) ; l != l_end ; ++l) - (*l)->accept(classifier); + (*l)->accept(classifier_builder); - if (classifier.includes_buildish || classifier.includes_non_post_runish) + auto classifier(classifier_builder.create()); + + if (classifier->includes_buildish || classifier->includes_non_post_runish) { bool normal(true); if (r.sanitised_dependency().spec().if_block()) @@ -283,7 +285,7 @@ namespace NAGIndex from(make_named_values<NAGIndex>( n::resolvent() = r.from_resolvent(), - n::role() = classifier.includes_fetch ? role_for_fetching(r.from_resolvent()) : nir_done + n::role() = classifier->includes_fetch ? role_for_fetching(r.from_resolvent()) : nir_done )); NAGIndex to(make_named_values<NAGIndex>( @@ -306,10 +308,10 @@ namespace nag->add_edge(from, to, make_named_values<NAGEdgeProperties>( n::always() = false, - n::build() = classifier.includes_buildish, - n::build_all_met() = r.already_met().is_true() || ! classifier.includes_buildish, - n::run() = classifier.includes_non_post_runish, - n::run_all_met() = r.already_met().is_true() || ! classifier.includes_non_post_runish + n::build() = classifier->includes_buildish, + n::build_all_met() = r.already_met().is_true() || ! classifier->includes_buildish, + n::run() = classifier->includes_non_post_runish, + n::run_all_met() = r.already_met().is_true() || ! classifier->includes_non_post_runish )); } else @@ -324,7 +326,7 @@ namespace )); } } - else if (classifier.includes_postish) + else if (classifier->includes_postish) { /* we won't add a backwards edge, since most post deps dep upon * the thing requiring them anyway */ diff --git a/paludis/resolver/sanitised_dependencies.cc b/paludis/resolver/sanitised_dependencies.cc index d4f38eddd..8439536d0 100644 --- a/paludis/resolver/sanitised_dependencies.cc +++ b/paludis/resolver/sanitised_dependencies.cc @@ -362,13 +362,13 @@ namespace SanitisedDependency make_sanitised(const PackageOrBlockDepSpec & spec) { std::stringstream adl, acs; - auto classifier(std::make_shared<LabelsClassifier>(env, our_id)); + auto classifier_builder(std::make_shared<LabelsClassifierBuilder>(env, our_id)); for (DependenciesLabelSequence::ConstIterator i((*labels_stack.begin())->begin()), i_end((*labels_stack.begin())->end()) ; i != i_end ; ++i) { adl << (adl.str().empty() ? "" : ", ") << stringify(**i); - (*i)->accept(*classifier); + (*i)->accept(*classifier_builder); } for (auto c(conditions_stack.begin()), c_end(conditions_stack.end()) ; @@ -379,7 +379,7 @@ namespace n::active_conditions_as_string() = acs.str(), n::active_dependency_labels() = *labels_stack.begin(), n::active_dependency_labels_as_string() = adl.str(), - n::active_dependency_labels_classifier() = classifier, + n::active_dependency_labels_classifier() = classifier_builder->create(), n::from_id() = our_id, n::metadata_key_human_name() = human_name, n::metadata_key_raw_name() = raw_name, @@ -564,7 +564,7 @@ SanitisedDependency::deserialise(Deserialisation & d, const std::shared_ptr<cons n::active_conditions_as_string() = v.member<std::string>("active_conditions_as_string"), n::active_dependency_labels() = make_null_shared_ptr(), n::active_dependency_labels_as_string() = v.member<std::string>("active_dependency_labels_as_string"), - n::active_dependency_labels_classifier() = v.member<std::shared_ptr<LabelsClassifier> >("active_dependency_labels_classifier"), + n::active_dependency_labels_classifier() = v.member<std::shared_ptr<const LabelsClassifier> >("active_dependency_labels_classifier"), n::from_id() = v.member<std::shared_ptr<const PackageID> >("from_id"), n::metadata_key_human_name() = v.member<std::string>("metadata_key_human_name"), n::metadata_key_raw_name() = v.member<std::string>("metadata_key_raw_name"), |