From 88c61324b30e75f8960192cf2207ee455db96080 Mon Sep 17 00:00:00 2001 From: Daniel Burrows Date: Tue, 9 Jun 2009 21:19:15 -0700 Subject: Add 3-way comparisons to the resolver layer instead of using operator<. A 3-way comparison is the traditional "return <0, =0, or >0" protocol. The implementation supports compile-time polymorphism to select the most appropriate comparison, defaulting to operator<. This yields a huge improvement in the program run-time, probably because the program compares lots of complex objects, especially things like imm::set objects that build their comparison from sub-comparisons. It would still be good to overload compare3<> on the types used in the aptitude resolver universe -- although the core types are simple enough that the compiler will probably be able to optimize the extra comparisons away (I hope, anyway). --- .../problemresolver/incremental_expression.h | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/generic/problemresolver/incremental_expression.h') diff --git a/src/generic/problemresolver/incremental_expression.h b/src/generic/problemresolver/incremental_expression.h index 8d7bd1bb..b62794ff 100644 --- a/src/generic/problemresolver/incremental_expression.h +++ b/src/generic/problemresolver/incremental_expression.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -123,6 +124,11 @@ public: return expr == other; } + int compare(const expression_weak_ref &other) const + { + return aptitude::util::compare3(expr, other.expr); + } + bool operator<(const expression_weak_ref &other) const { return expr < other.expr; @@ -131,6 +137,23 @@ public: ~expression_weak_ref(); }; +namespace aptitude +{ + namespace util + { + template + class compare3_f > + { + public: + int operator()(const expression_weak_ref &r1, + const expression_weak_ref &r2) const + { + return r1.compare(r2); + } + }; + } +} + template class expression_container; -- cgit v1.2.3