diff options
author | 2010-12-17 23:09:25 +0000 | |
---|---|---|
committer | 2010-12-17 23:09:25 +0000 | |
commit | 9f74662de1a518c3a2b4fdefee586fcc9fd5bce7 (patch) | |
tree | 6099c2b232272a767dc4f9d68d94681be2f957de | |
parent | 1ee6e1e1783173f3761f7edaf02f2767cfe2bf4f (diff) | |
download | paludis-9f74662de1a518c3a2b4fdefee586fcc9fd5bce7.tar.gz paludis-9f74662de1a518c3a2b4fdefee586fcc9fd5bce7.tar.xz |
Share slot keys
-rw-r--r-- | paludis/repositories/e/Makefile.am | 2 | ||||
-rw-r--r-- | paludis/repositories/e/e_key.cc | 51 | ||||
-rw-r--r-- | paludis/repositories/e/e_key.hh | 17 | ||||
-rw-r--r-- | paludis/repositories/e/e_slot_key.cc | 124 | ||||
-rw-r--r-- | paludis/repositories/e/e_slot_key.hh | 50 | ||||
-rw-r--r-- | paludis/repositories/e/ebuild_id.cc | 5 |
6 files changed, 179 insertions, 70 deletions
diff --git a/paludis/repositories/e/Makefile.am b/paludis/repositories/e/Makefile.am index 309fd5afd..46235845e 100644 --- a/paludis/repositories/e/Makefile.am +++ b/paludis/repositories/e/Makefile.am @@ -49,6 +49,7 @@ noinst_HEADERS = \ e_repository_params-se.hh \ e_repository_params.hh \ e_repository_sets.hh \ + e_slot_key.hh \ e_stripper.hh \ eapi.hh \ eapi-fwd.hh \ @@ -119,6 +120,7 @@ libpaludiserepository_la_SOURCES = \ e_repository_news.cc \ e_repository_params.cc \ e_repository_sets.cc \ + e_slot_key.cc \ e_stripper.cc \ eapi.cc \ eapi_phase.cc \ diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc index 921a503a7..db3622e1e 100644 --- a/paludis/repositories/e/e_key.cc +++ b/paludis/repositories/e/e_key.cc @@ -1224,54 +1224,3 @@ EMTimeKey::type() const return _imp->type; } -namespace paludis -{ - template <> - struct Imp<ESlotKey> - { - const SlotName value; - const std::shared_ptr<const EAPIMetadataVariable> variable; - const MetadataKeyType type; - - Imp(const SlotName & v, const std::shared_ptr<const EAPIMetadataVariable> & m, const MetadataKeyType t) : - value(v), - variable(m), - type(t) - { - } - }; -} - -ESlotKey::ESlotKey(const std::shared_ptr<const EAPIMetadataVariable> & m, const std::string & v, const MetadataKeyType t) : - Pimp<ESlotKey>(SlotName(v), m, t) -{ -} - -ESlotKey::~ESlotKey() -{ -} - -const SlotName -ESlotKey::value() const -{ - return _imp->value; -} - -const std::string -ESlotKey::raw_name() const -{ - return _imp->variable->name(); -} - -const std::string -ESlotKey::human_name() const -{ - return _imp->variable->description(); -} - -MetadataKeyType -ESlotKey::type() const -{ - return _imp->type; -} - diff --git a/paludis/repositories/e/e_key.hh b/paludis/repositories/e/e_key.hh index e43b71d6d..62f344dee 100644 --- a/paludis/repositories/e/e_key.hh +++ b/paludis/repositories/e/e_key.hh @@ -339,23 +339,6 @@ namespace paludis virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result)); }; - - class ESlotKey : - public MetadataValueKey<SlotName>, - private Pimp<ESlotKey> - { - public: - ESlotKey( - const std::shared_ptr<const EAPIMetadataVariable> &, - const std::string &, const MetadataKeyType); - ~ESlotKey(); - - virtual const SlotName value() const PALUDIS_ATTRIBUTE((warn_unused_result)); - - virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); - virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result)); - virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result)); - }; } } diff --git a/paludis/repositories/e/e_slot_key.cc b/paludis/repositories/e/e_slot_key.cc new file mode 100644 index 000000000..aeaee8dcc --- /dev/null +++ b/paludis/repositories/e/e_slot_key.cc @@ -0,0 +1,124 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/repositories/e/e_slot_key.hh> +#include <paludis/repositories/e/eapi.hh> + +#include <paludis/util/singleton-impl.hh> +#include <paludis/util/hashes.hh> +#include <paludis/util/singleton-impl.hh> +#include <paludis/util/pimp-impl.hh> + +#include <paludis/name.hh> + +#include <tuple> +#include <unordered_map> + +using namespace paludis; +using namespace paludis::erepository; + +namespace +{ + struct ESlotKey : + MetadataValueKey<SlotName> + { + const SlotName slot_value; + const std::shared_ptr<const EAPIMetadataVariable> variable; + const MetadataKeyType key_type; + + ESlotKey(const SlotName & v, const std::shared_ptr<const EAPIMetadataVariable> & m, const MetadataKeyType t) : + slot_value(v), + variable(m), + key_type(t) + { + } + + ~ESlotKey() + { + } + + virtual const SlotName value() const + { + return slot_value; + } + + virtual const std::string raw_name() const + { + return variable->name(); + } + + virtual const std::string human_name() const + { + return variable->description(); + } + + virtual MetadataKeyType type() const + { + return key_type; + } + }; + + typedef std::tuple<std::shared_ptr<const EAPIMetadataVariable>, std::string, MetadataKeyType> ESlotKeyStoreIndex; + + struct ESlotKeyStoreHash + { + std::size_t operator() (const ESlotKeyStoreIndex & p) const + { + return + Hash<std::string>()(std::get<0>(p)->description()) ^ + std::get<0>(p)->flat_list_index() ^ + Hash<std::string>()(std::get<0>(p)->name()) ^ + Hash<std::string>()(std::get<1>(p)) ^ + static_cast<int>(std::get<2>(p)); + } + }; +} + +namespace paludis +{ + template <> + struct Imp<ESlotKeyStore> + { + mutable Mutex mutex; + mutable std::unordered_map<ESlotKeyStoreIndex, std::shared_ptr<const ESlotKey>, ESlotKeyStoreHash> store; + }; +} + +ESlotKeyStore::ESlotKeyStore() : + Pimp<ESlotKeyStore>() +{ +} + +ESlotKeyStore::~ESlotKeyStore() = default; + +const std::shared_ptr<const MetadataValueKey<SlotName> > +ESlotKeyStore::fetch( + const std::shared_ptr<const EAPIMetadataVariable> & v, + const std::string & s, + const MetadataKeyType t) const +{ + Lock lock(_imp->mutex); + + ESlotKeyStoreIndex x(v, s, t); + auto i(_imp->store.find(x)); + if (i == _imp->store.end()) + i = _imp->store.insert(std::make_pair(x, std::make_shared<const ESlotKey>(SlotName(s), v, t))).first; + return i->second; +} + diff --git a/paludis/repositories/e/e_slot_key.hh b/paludis/repositories/e/e_slot_key.hh new file mode 100644 index 000000000..9402b1cd3 --- /dev/null +++ b/paludis/repositories/e/e_slot_key.hh @@ -0,0 +1,50 @@ +/* vim: set sw=4 sts=4 et foldmethod=syntax : */ + +/* + * Copyright (c) 2010 Ciaran McCreesh + * + * 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 + * Public License version 2, as published by the Free Software Foundation. + * + * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <paludis/metadata_key.hh> +#include <paludis/util/singleton.hh> +#include <paludis/repositories/e/eapi-fwd.hh> + +#ifndef PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_E_SLOT_KEY_HH +#define PALUDIS_GUARD_PALUDIS_REPOSITORIES_E_E_SLOT_KEY_HH 1 + +namespace paludis +{ + namespace erepository + { + class ESlotKeyStore : + private Pimp<ESlotKeyStore>, + public Singleton<ESlotKeyStore> + { + friend class Singleton<ESlotKeyStore>; + + private: + ESlotKeyStore(); + ~ESlotKeyStore(); + + public: + const std::shared_ptr<const MetadataValueKey<SlotName> > fetch( + const std::shared_ptr<const EAPIMetadataVariable> &, + const std::string &, + const MetadataKeyType) const PALUDIS_ATTRIBUTE((warn_unused_result)); + }; + } +} + +#endif diff --git a/paludis/repositories/e/ebuild_id.cc b/paludis/repositories/e/ebuild_id.cc index 28509b6fe..53873718a 100644 --- a/paludis/repositories/e/ebuild_id.cc +++ b/paludis/repositories/e/ebuild_id.cc @@ -23,6 +23,7 @@ #include <paludis/repositories/e/e_repository_params.hh> #include <paludis/repositories/e/eapi_phase.hh> #include <paludis/repositories/e/e_key.hh> +#include <paludis/repositories/e/e_slot_key.hh> #include <paludis/repositories/e/e_choices_key.hh> #include <paludis/repositories/e/e_mask.hh> #include <paludis/repositories/e/eapi.hh> @@ -125,7 +126,7 @@ namespace paludis mutable bool has_keys; mutable bool has_masks; - mutable std::shared_ptr<const ESlotKey> slot; + mutable std::shared_ptr<const MetadataValueKey<SlotName> > slot; mutable std::shared_ptr<const LiteralMetadataValueKey<FSPath> > fs_location; mutable std::shared_ptr<const LiteralMetadataValueKey<std::string> > short_description; mutable std::shared_ptr<const LiteralMetadataValueKey<std::string> > long_description; @@ -1144,7 +1145,7 @@ void EbuildID::load_slot(const std::shared_ptr<const EAPIMetadataVariable> & m, const std::string & v) const { Lock l(_imp->mutex); - _imp->slot = std::make_shared<ESlotKey>(m, v, mkt_internal); + _imp->slot = ESlotKeyStore::get_instance()->fetch(m, v, mkt_internal); add_metadata_key(_imp->slot); } |