aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-21 06:26:02 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-21 06:26:02 +0000
commit4e76c6151bc6abbadeb755904ac517d85b99abff (patch)
tree7da0a81d362ce34a1ee2db5e6fa6ed04c142ebae
parenteed1e659a70604de61e6b27d84ea9b7f88951205 (diff)
downloadpaludis-4e76c6151bc6abbadeb755904ac517d85b99abff.tar.gz
paludis-4e76c6151bc6abbadeb755904ac517d85b99abff.tar.xz
Make --with-dependencies and --with-unused-dependencies a lot faster
-rw-r--r--paludis/uninstall_list.cc60
1 files changed, 46 insertions, 14 deletions
diff --git a/paludis/uninstall_list.cc b/paludis/uninstall_list.cc
index a78312c..1e60ebc 100644
--- a/paludis/uninstall_list.cc
+++ b/paludis/uninstall_list.cc
@@ -26,12 +26,25 @@ using namespace paludis;
#include <paludis/util/collection_concrete.hh>
#include <paludis/util/join.hh>
#include <paludis/util/log.hh>
+#include <paludis/hashed_containers.hh>
#include <list>
#include <algorithm>
namespace paludis
{
template<>
+ class CRCHash<PackageDatabaseEntry> :
+ public CRCHash<std::string>
+ {
+ public:
+ /// Hash function.
+ std::size_t operator() (const PackageDatabaseEntry & val) const
+ {
+ return CRCHash<std::string>::operator() (stringify(val));
+ }
+ };
+
+ template<>
struct Implementation<UninstallList> :
InternalCounted<Implementation<UninstallList> >
{
@@ -39,6 +52,9 @@ namespace paludis
UninstallListOptions options;
std::list<UninstallListEntry> uninstall_list;
+ mutable MakeHashedMap<PackageDatabaseEntry, PackageDatabaseEntryCollection::ConstPointer>::Type
+ dep_collector_cache;
+
Implementation(const Environment * const e, const UninstallListOptions & o) :
env(e),
options(o)
@@ -215,13 +231,22 @@ UninstallList::collect_depped_upon(PackageDatabaseEntryCollection::ConstPointer
i != i_end ; ++i)
{
Context local_context("When collecting depended upon packages for '" + stringify(*i) + "':");
- DepCollector c(_imp->env, *i);
- VersionMetadata::ConstPointer metadata(_imp->env->package_database()->fetch_repository(
- i->repository)->version_metadata(i->name, i->version));
- metadata->deps.build_depend()->accept(&c);
- metadata->deps.run_depend()->accept(&c);
- metadata->deps.post_depend()->accept(&c);
- result->insert(c.matches->begin(), c.matches->end());
+
+ MakeHashedMap<PackageDatabaseEntry, PackageDatabaseEntryCollection::ConstPointer>::Type::const_iterator
+ cache(_imp->dep_collector_cache.find(*i));
+ if (cache == _imp->dep_collector_cache.end())
+ {
+ DepCollector c(_imp->env, *i);
+ VersionMetadata::ConstPointer metadata(_imp->env->package_database()->fetch_repository(
+ i->repository)->version_metadata(i->name, i->version));
+ metadata->deps.build_depend()->accept(&c);
+ metadata->deps.run_depend()->accept(&c);
+ metadata->deps.post_depend()->accept(&c);
+ cache = _imp->dep_collector_cache.insert(std::make_pair(*i,
+ PackageDatabaseEntryCollection::ConstPointer(c.matches))).first;
+ }
+
+ result->insert(cache->second->begin(), cache->second->end());
}
return result;
@@ -302,14 +327,21 @@ UninstallList::add_dependencies(const PackageDatabaseEntry & e)
{
Context local_context("When seeing whether '" + stringify(*i) + "' has a dep:");
- DepCollector c(_imp->env, *i);
- VersionMetadata::ConstPointer metadata(_imp->env->package_database()->fetch_repository(
- i->repository)->version_metadata(i->name, i->version));
- metadata->deps.build_depend()->accept(&c);
- metadata->deps.run_depend()->accept(&c);
- metadata->deps.post_depend()->accept(&c);
+ MakeHashedMap<PackageDatabaseEntry, PackageDatabaseEntryCollection::ConstPointer>::Type::const_iterator
+ cache(_imp->dep_collector_cache.find(*i));
+ if (cache == _imp->dep_collector_cache.end())
+ {
+ DepCollector c(_imp->env, *i);
+ VersionMetadata::ConstPointer metadata(_imp->env->package_database()->fetch_repository(
+ i->repository)->version_metadata(i->name, i->version));
+ metadata->deps.build_depend()->accept(&c);
+ metadata->deps.run_depend()->accept(&c);
+ metadata->deps.post_depend()->accept(&c);
+ cache = _imp->dep_collector_cache.insert(std::make_pair(*i,
+ PackageDatabaseEntryCollection::ConstPointer(c.matches))).first;
+ }
- if (c.matches->end() == c.matches->find(e))
+ if (cache->second->end() == cache->second->find(e))
continue;
add(*i);