aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-11 22:14:44 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-03-11 22:14:44 +0000
commit582f22e2fb6a4c7c43fba759aa7d86ec6b4fd233 (patch)
tree6e46b2d799c7855ba78dbf30e0fb1945e424351f
parent5bc0738f9d8bf4085952e05961ff9380fa36e0c9 (diff)
downloadpaludis-582f22e2fb6a4c7c43fba759aa7d86ec6b4fd233.tar.gz
paludis-582f22e2fb6a4c7c43fba759aa7d86ec6b4fd233.tar.xz
Use pools for E choice values
-rw-r--r--paludis/repositories/e/e_choice_value.cc67
-rw-r--r--paludis/repositories/e/e_choice_value.hh19
-rw-r--r--paludis/repositories/e/e_installed_repository_id.cc2
-rw-r--r--paludis/repositories/e/ebuild_id.cc2
4 files changed, 21 insertions, 69 deletions
diff --git a/paludis/repositories/e/e_choice_value.cc b/paludis/repositories/e/e_choice_value.cc
index a89866f..1ea1f50 100644
--- a/paludis/repositories/e/e_choice_value.cc
+++ b/paludis/repositories/e/e_choice_value.cc
@@ -20,11 +20,9 @@
#include <paludis/repositories/e/e_choice_value.hh>
#include <paludis/repositories/e/use_desc.hh>
#include <paludis/util/make_null_shared_ptr.hh>
-#include <paludis/util/hashes.hh>
-#include <paludis/util/mutex.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/singleton-impl.hh>
-#include <unordered_map>
+#include <paludis/util/pool-impl.hh>
using namespace paludis;
using namespace paludis::erepository;
@@ -111,9 +109,10 @@ EChoiceValue::permitted_parameter_values() const
return make_null_shared_ptr();
}
-namespace
+namespace paludis
{
- struct EChoiceValueParamsHash
+ template <>
+ struct Hash<EChoiceValueParams>
{
Hash<ChoiceNameWithPrefix> choice_name_with_prefix_hash;
Hash<ChoicePrefixName> choice_prefix_name_hash;
@@ -139,54 +138,24 @@ namespace
}
};
- struct EChoiceValueParamsCompare
+ bool operator== (const EChoiceValueParams & a, const EChoiceValueParams & b)
{
- bool operator() (const EChoiceValueParams & a, const EChoiceValueParams & b) const
- {
- return true
- && (a.choice_name_with_prefix() == b.choice_name_with_prefix())
- && (a.choice_prefix_name() == b.choice_prefix_name())
- && (a.description() == b.description())
- && (a.enabled() == b.enabled())
- && (a.enabled_by_default() == b.enabled_by_default())
- && (a.explicitly_listed() == b.explicitly_listed())
- && (a.locked() == b.locked())
- && (a.unprefixed_choice_name() == b.unprefixed_choice_name())
- ;
- }
- };
-
- typedef std::unordered_map<EChoiceValueParams, std::shared_ptr<const EChoiceValue>, EChoiceValueParamsHash, EChoiceValueParamsCompare> Store;
+ return true
+ && (a.choice_name_with_prefix() == b.choice_name_with_prefix())
+ && (a.choice_prefix_name() == b.choice_prefix_name())
+ && (a.description() == b.description())
+ && (a.enabled() == b.enabled())
+ && (a.enabled_by_default() == b.enabled_by_default())
+ && (a.explicitly_listed() == b.explicitly_listed())
+ && (a.locked() == b.locked())
+ && (a.unprefixed_choice_name() == b.unprefixed_choice_name())
+ ;
+ }
}
-namespace paludis
-{
- template <>
- struct Imp<EChoiceValueStore>
- {
- mutable Mutex mutex;
- mutable Store store;
- };
-}
-
-EChoiceValueStore::EChoiceValueStore() :
- _imp()
-{
-}
-
-EChoiceValueStore::~EChoiceValueStore() = default;
-
const std::shared_ptr<const ChoiceValue>
-EChoiceValueStore::fetch(const EChoiceValueParams & p) const
+paludis::erepository::create_e_choice_value(const EChoiceValueParams & p)
{
- Lock lock(_imp->mutex);
- auto i(_imp->store.find(p));
- if (i == _imp->store.end())
- i = _imp->store.insert(std::make_pair(p, std::make_shared<EChoiceValue>(p))).first;
-
- return i->second;
+ return Pool<EChoiceValue>::get_instance()->create(p);
}
-template class Pimp<erepository::EChoiceValueStore>;
-template class Singleton<erepository::EChoiceValueStore>;
-
diff --git a/paludis/repositories/e/e_choice_value.hh b/paludis/repositories/e/e_choice_value.hh
index 829cb3c..7b33e63 100644
--- a/paludis/repositories/e/e_choice_value.hh
+++ b/paludis/repositories/e/e_choice_value.hh
@@ -22,7 +22,6 @@
#include <paludis/util/attributes.hh>
#include <paludis/util/named_value.hh>
-#include <paludis/util/singleton.hh>
#include <paludis/choice.hh>
#include <paludis/name.hh>
#include <functional>
@@ -56,24 +55,8 @@ namespace paludis
NamedValue<n::unprefixed_choice_name, UnprefixedChoiceName> unprefixed_choice_name;
};
- class PALUDIS_VISIBLE EChoiceValueStore :
- public Singleton<EChoiceValueStore>
- {
- friend class Singleton<EChoiceValueStore>;
-
- private:
- EChoiceValueStore();
- ~EChoiceValueStore();
-
- Pimp<EChoiceValueStore> _imp;
-
- public:
- const std::shared_ptr<const ChoiceValue> fetch(const EChoiceValueParams &) const PALUDIS_ATTRIBUTE((warn_unused_result));
- };
+ const std::shared_ptr<const ChoiceValue> create_e_choice_value(const EChoiceValueParams &);
}
-
- extern template class Pimp<erepository::EChoiceValueStore>;
- extern template class Singleton<erepository::EChoiceValueStore>;
}
#endif
diff --git a/paludis/repositories/e/e_installed_repository_id.cc b/paludis/repositories/e/e_installed_repository_id.cc
index ae7b713..ec8cf99 100644
--- a/paludis/repositories/e/e_installed_repository_id.cc
+++ b/paludis/repositories/e/e_installed_repository_id.cc
@@ -1063,7 +1063,7 @@ EInstalledRepositoryID::make_choice_value(const std::shared_ptr<const Choice> &
if (raw_use_key())
enabled = (raw_use_key()->value()->end() != raw_use_key()->value()->find(name_with_prefix));
- return EChoiceValueStore::get_instance()->fetch(make_named_values<EChoiceValueParams>(
+ return create_e_choice_value(make_named_values<EChoiceValueParams>(
n::choice_name_with_prefix() = ChoiceNameWithPrefix(name_with_prefix),
n::choice_prefix_name() = c->prefix(),
n::description() = override_description,
diff --git a/paludis/repositories/e/ebuild_id.cc b/paludis/repositories/e/ebuild_id.cc
index 8ce5838..b0e5b65 100644
--- a/paludis/repositories/e/ebuild_id.cc
+++ b/paludis/repositories/e/ebuild_id.cc
@@ -1508,7 +1508,7 @@ EbuildID::make_choice_value(
}
}
- return EChoiceValueStore::get_instance()->fetch(make_named_values<EChoiceValueParams>(
+ return create_e_choice_value(make_named_values<EChoiceValueParams>(
n::choice_name_with_prefix() = ChoiceNameWithPrefix(name_with_prefix),
n::choice_prefix_name() = choice->prefix(),
n::description() = get_description(e_repo->use_desc(), override_description, name(), choice->prefix(), value_name),