aboutsummaryrefslogtreecommitdiff
path: root/paludis/repositories/e/eclass_mtimes.cc
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-08-12 19:25:21 +0100
committerAvatar David Leverton <levertond@googlemail.com> 2008-08-16 21:43:31 +0100
commit767fb3805f9629ebc36888a35023eda943089819 (patch)
tree99f37ccbbd138ea72ea435b4005b57e5aa9698db /paludis/repositories/e/eclass_mtimes.cc
parent9035495cebefab9829c69d8abea3caf0e8b6ff2b (diff)
downloadpaludis-767fb3805f9629ebc36888a35023eda943089819.tar.gz
paludis-767fb3805f9629ebc36888a35023eda943089819.tar.xz
Support for Portage's flat_hash cache format. Fixes: ticket:630
Use flat_hash for the write_cache, and drop flat_list support for non-Gentoo EAPIs.
Diffstat (limited to 'paludis/repositories/e/eclass_mtimes.cc')
-rw-r--r--paludis/repositories/e/eclass_mtimes.cc79
1 files changed, 56 insertions, 23 deletions
diff --git a/paludis/repositories/e/eclass_mtimes.cc b/paludis/repositories/e/eclass_mtimes.cc
index 428dc0b02..e8136c73e 100644
--- a/paludis/repositories/e/eclass_mtimes.cc
+++ b/paludis/repositories/e/eclass_mtimes.cc
@@ -2,6 +2,7 @@
/*
* Copyright (c) 2006, 2007, 2008 Ciaran McCreesh
+ * Copyright (c) 2008 David Leverton
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -18,6 +19,9 @@
*/
#include "eclass_mtimes.hh"
+#include <paludis/repositories/e/e_repository.hh>
+#include <paludis/repositories/e/layout.hh>
+#include <paludis/name.hh>
#include <paludis/util/private_implementation_pattern-impl.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/fs_entry.hh>
@@ -28,24 +32,58 @@
using namespace paludis;
+namespace
+{
+ struct Cache
+ {
+ std::tr1::shared_ptr<const FSEntrySequence> dirs;
+ std::tr1::unordered_map<std::string, FSEntry, Hash<std::string> > files;
+
+ Cache(const std::tr1::shared_ptr<const FSEntrySequence> & d) :
+ dirs(d)
+ {
+ }
+ };
+
+ const FSEntry *
+ lookup(const std::string & e, Cache & c)
+ {
+ std::tr1::unordered_map<std::string, FSEntry, Hash<std::string> >::const_iterator i(c.files.find(e));
+ if (i != c.files.end())
+ return & i->second;
+
+ for (FSEntrySequence::ReverseConstIterator d(c.dirs->rbegin()),
+ d_end(c.dirs->rend()) ; d != d_end ; ++d)
+ {
+ FSEntry f(*d / e);
+ if (f.exists())
+ return & c.files.insert(std::make_pair(e, f)).first->second;
+ }
+
+ return 0;
+ }
+}
+
namespace paludis
{
template<>
struct Implementation<EclassMtimes>
{
- std::tr1::shared_ptr<const FSEntrySequence> eclass_dirs;
+ const ERepository * repo;
+ mutable Cache eclasses;
+ mutable std::tr1::unordered_map<QualifiedPackageName, Cache, Hash<QualifiedPackageName> > exlibs;
mutable Mutex mutex;
- mutable std::tr1::unordered_map<std::string, time_t, Hash<std::string> > eclass_mtimes;
- Implementation(std::tr1::shared_ptr<const FSEntrySequence> d) :
- eclass_dirs(d)
+ Implementation(const ERepository * r, const std::tr1::shared_ptr<const FSEntrySequence> & d) :
+ repo(r),
+ eclasses(d)
{
}
};
}
-EclassMtimes::EclassMtimes(std::tr1::shared_ptr<const FSEntrySequence> d) :
- PrivateImplementationPattern<EclassMtimes>(new Implementation<EclassMtimes>(d))
+EclassMtimes::EclassMtimes(const ERepository * r, const std::tr1::shared_ptr<const FSEntrySequence> & d) :
+ PrivateImplementationPattern<EclassMtimes>(new Implementation<EclassMtimes>(r, d))
{
}
@@ -53,25 +91,20 @@ EclassMtimes::~EclassMtimes()
{
}
-time_t
-EclassMtimes::mtime(const std::string & e) const
+const FSEntry *
+EclassMtimes::eclass(const std::string & e) const
{
Lock l(_imp->mutex);
+ return lookup(e + ".eclass", _imp->eclasses);
+}
- std::tr1::unordered_map<std::string, time_t, Hash<std::string> >::const_iterator i(_imp->eclass_mtimes.find(e));
- if (i != _imp->eclass_mtimes.end())
- return i->second;
-
- time_t r(0);
- for (FSEntrySequence::ConstIterator d(_imp->eclass_dirs->begin()),
- d_end(_imp->eclass_dirs->end()) ; d != d_end ; ++d)
- {
- FSEntry f(*d / (e + ".eclass"));
- if (f.exists())
- r = std::max(r, f.mtime());
- }
-
- _imp->eclass_mtimes.insert(std::make_pair(e, r));
- return r;
+const FSEntry *
+EclassMtimes::exlib(const std::string & e, const QualifiedPackageName & qpn) const
+{
+ Lock l(_imp->mutex);
+ std::tr1::unordered_map<QualifiedPackageName, Cache, Hash<QualifiedPackageName> >::iterator cache(_imp->exlibs.find(qpn));
+ if (_imp->exlibs.end() == cache)
+ cache = _imp->exlibs.insert(std::make_pair(qpn, Cache(_imp->repo->layout()->exlibsdirs(qpn)))).first;
+ return lookup(e + ".exlib", cache->second);
}