aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-01-23 12:51:46 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-01-23 12:51:46 +0000
commit653947f40135832b5e388a90f22adf069584034a (patch)
tree1347c3f78018092ff08df987f61479c9b950ac5c
parent62a3e9ef98827094e0daa27418c4a08677ba1458 (diff)
downloadpaludis-653947f40135832b5e388a90f22adf069584034a.tar.gz
paludis-653947f40135832b5e388a90f22adf069584034a.tar.xz
Share unaccepted keys
-rw-r--r--paludis/repositories/e/e_mask.cc61
-rw-r--r--paludis/repositories/e/e_mask.hh22
-rw-r--r--paludis/repositories/e/ebuild_id.cc14
3 files changed, 81 insertions, 16 deletions
diff --git a/paludis/repositories/e/e_mask.cc b/paludis/repositories/e/e_mask.cc
index e2aba5b..a2ff30a 100644
--- a/paludis/repositories/e/e_mask.cc
+++ b/paludis/repositories/e/e_mask.cc
@@ -19,10 +19,31 @@
#include <paludis/repositories/e/e_mask.hh>
#include <paludis/util/pimp-impl.hh>
+#include <paludis/util/singleton-impl.hh>
+#include <paludis/util/hashes.hh>
+#include <unordered_map>
using namespace paludis;
using namespace paludis::erepository;
+namespace
+{
+ class EUnacceptedMask :
+ public UnacceptedMask
+ {
+ private:
+ Pimp<EUnacceptedMask> _imp;
+
+ public:
+ EUnacceptedMask(const char, const std::string &, const std::string &);
+ ~EUnacceptedMask();
+
+ char key() const;
+ const std::string description() const;
+ const std::string unaccepted_key_name() const;
+ };
+}
+
namespace paludis
{
template <>
@@ -160,3 +181,43 @@ ERepositoryMask::mask_key_name() const
return _imp->mask_key_name;
}
+namespace
+{
+ typedef std::tuple<char, std::string, std::string> EUnacceptedMaskIndex;
+}
+
+namespace paludis
+{
+ template <>
+ struct Imp<EUnacceptedMaskStore>
+ {
+ mutable Mutex mutex;
+ mutable std::unordered_map<EUnacceptedMaskIndex, std::shared_ptr<const UnacceptedMask>, Hash<EUnacceptedMaskIndex> > store;
+ };
+}
+
+EUnacceptedMaskStore::EUnacceptedMaskStore() :
+ _imp()
+{
+}
+
+EUnacceptedMaskStore::~EUnacceptedMaskStore()
+{
+}
+
+const std::shared_ptr<const UnacceptedMask>
+EUnacceptedMaskStore::fetch(const char c, const std::string & s, const std::string & k)
+{
+ EUnacceptedMaskIndex index(c, s, k);
+
+ Lock lock(_imp->mutex);
+ auto i(_imp->store.find(index));
+ if (i == _imp->store.end())
+ i = _imp->store.insert(std::make_pair(index, std::make_shared<EUnacceptedMask>(c, s, k))).first;
+
+ return i->second;
+}
+
+template class Singleton<EUnacceptedMaskStore>;
+template class Pimp<EUnacceptedMaskStore>;
+
diff --git a/paludis/repositories/e/e_mask.hh b/paludis/repositories/e/e_mask.hh
index 7ca68f8..c550fa8 100644
--- a/paludis/repositories/e/e_mask.hh
+++ b/paludis/repositories/e/e_mask.hh
@@ -22,24 +22,25 @@
#include <paludis/mask.hh>
#include <paludis/util/pimp.hh>
+#include <paludis/util/singleton.hh>
namespace paludis
{
namespace erepository
{
- class EUnacceptedMask :
- public UnacceptedMask
+ class EUnacceptedMaskStore :
+ public Singleton<EUnacceptedMaskStore>
{
+ friend class Singleton<EUnacceptedMaskStore>;
+
private:
- Pimp<EUnacceptedMask> _imp;
+ Pimp<EUnacceptedMaskStore> _imp;
- public:
- EUnacceptedMask(const char, const std::string &, const std::string &);
- ~EUnacceptedMask();
+ EUnacceptedMaskStore();
+ ~EUnacceptedMaskStore();
- char key() const;
- const std::string description() const;
- const std::string unaccepted_key_name() const;
+ public:
+ const std::shared_ptr<const UnacceptedMask> fetch(const char, const std::string &, const std::string &);
};
class EUnsupportedMask :
@@ -72,6 +73,9 @@ namespace paludis
const std::string mask_key_name() const;
};
}
+
+ extern template class Singleton<erepository::EUnacceptedMaskStore>;
+ extern template class Pimp<erepository::EUnacceptedMaskStore>;
}
#endif
diff --git a/paludis/repositories/e/ebuild_id.cc b/paludis/repositories/e/ebuild_id.cc
index 04c2930..86933dd 100644
--- a/paludis/repositories/e/ebuild_id.cc
+++ b/paludis/repositories/e/ebuild_id.cc
@@ -530,16 +530,16 @@ EbuildID::need_masks_added() const
{
if (! _imp->environment->accept_keywords(keywords_key()->value(), shared_from_this()))
{
- add_mask(std::make_shared<EUnacceptedMask>('K',
- DistributionData::get_instance()->distribution_from_string(
- _imp->environment->distribution())->concept_keyword(), keywords_key()->raw_name()));
+ add_mask(EUnacceptedMaskStore::get_instance()->fetch('K',
+ DistributionData::get_instance()->distribution_from_string(
+ _imp->environment->distribution())->concept_keyword(), keywords_key()->raw_name()));
}
else if (keywords_key()->value()->end() == std::find_if(keywords_key()->value()->begin(),
keywords_key()->value()->end(), &is_stable_keyword))
{
add_overridden_mask(std::make_shared<OverriddenMask>(
make_named_values<OverriddenMask>(
- n::mask() = std::make_shared<EUnacceptedMask>('~',
+ n::mask() = EUnacceptedMaskStore::get_instance()->fetch('~',
DistributionData::get_instance()->distribution_from_string(
_imp->environment->distribution())->concept_keyword() + " (unstable accepted)", keywords_key()->raw_name()),
n::override_reason() = mro_accepted_unstable
@@ -552,9 +552,9 @@ EbuildID::need_masks_added() const
LicenceChecker c(_imp->environment, &Environment::accept_license, shared_from_this());
license_key()->value()->top()->accept(c);
if (! c.ok)
- add_mask(std::make_shared<EUnacceptedMask>('L',
- DistributionData::get_instance()->distribution_from_string(
- _imp->environment->distribution())->concept_license(), license_key()->raw_name()));
+ add_mask(EUnacceptedMaskStore::get_instance()->fetch('L',
+ DistributionData::get_instance()->distribution_from_string(
+ _imp->environment->distribution())->concept_license(), license_key()->raw_name()));
}
if (! _imp->environment->unmasked_by_user(shared_from_this()))