mirror of
https://github.com/holub/mame
synced 2025-10-04 16:34:53 +03:00
netlist: more structure for caches. (nw)
This commit is contained in:
parent
df172ffb13
commit
4f71e124d5
@ -25,39 +25,6 @@
|
||||
|
||||
namespace netlist
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
//static plib::mempool *pool()
|
||||
//{
|
||||
// static plib::mempool s_pool(655360, 32);
|
||||
// return &s_pool;
|
||||
//}
|
||||
|
||||
#if 0
|
||||
void * object_t::operator new (size_t size)
|
||||
{
|
||||
void *ret = nullptr;
|
||||
if ((USE_MEMPOOL))
|
||||
ret = pool()->alloc(size);
|
||||
else
|
||||
ret = ::operator new(size);
|
||||
return ret;
|
||||
}
|
||||
void object_t::operator delete (void * mem)
|
||||
{
|
||||
if (mem)
|
||||
{
|
||||
//if ((USE_MEMPOOL))
|
||||
// pool()->free(mem);
|
||||
//else
|
||||
::operator delete(mem);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// logic_family_ttl_t
|
||||
@ -187,22 +154,6 @@ void detail::queue_t::on_post_load(plib::state_manager_t &manager)
|
||||
detail::netlist_ref::netlist_ref(netlist_state_t &nl)
|
||||
: m_netlist(nl.exec()) { }
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// object_t
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
detail::object_t::object_t(const pstring &aname)
|
||||
// : m_name(aname)
|
||||
{
|
||||
name_hash().insert({this, aname});
|
||||
}
|
||||
|
||||
pstring detail::object_t::name() const
|
||||
{
|
||||
return name_hash().find(this)->second;
|
||||
//return m_name;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
// device_object_t
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -398,6 +398,32 @@ namespace netlist
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename C, typename T>
|
||||
struct property_store_t
|
||||
{
|
||||
static void add(const C *obj, const T &aname)
|
||||
{
|
||||
store().insert({obj, aname});
|
||||
}
|
||||
|
||||
static const T get(const C *obj)
|
||||
{
|
||||
return store().find(obj)->second;
|
||||
}
|
||||
|
||||
static void remove(const C *obj)
|
||||
{
|
||||
store().erase(store().find(obj));
|
||||
}
|
||||
|
||||
static std::unordered_map<const C *, T> &store()
|
||||
{
|
||||
static std::unordered_map<const C *, T> lstore;
|
||||
return lstore;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// object_t
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -417,35 +443,32 @@ namespace netlist
|
||||
*
|
||||
* Every class derived from the object_t class must have a name.
|
||||
*/
|
||||
explicit object_t(const pstring &aname /*!< string containing name of the object */);
|
||||
explicit object_t(const pstring &aname /*!< string containing name of the object */)
|
||||
{
|
||||
props::add(this, aname);
|
||||
}
|
||||
|
||||
COPYASSIGNMOVE(object_t, delete)
|
||||
/*! return name of the object
|
||||
*
|
||||
* \returns name of the object.
|
||||
*/
|
||||
pstring name() const;
|
||||
pstring name() const
|
||||
{
|
||||
return props::get(this);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void * operator new (size_t size, void *ptr) { plib::unused_var(size); return ptr; }
|
||||
void operator delete (void *ptr, void *) { plib::unused_var(ptr); }
|
||||
void * operator new (size_t size) = delete;
|
||||
void operator delete (void * mem) = delete;
|
||||
#endif
|
||||
protected:
|
||||
|
||||
using props = property_store_t<object_t, pstring>;
|
||||
|
||||
// only childs should be destructible
|
||||
~object_t() noexcept
|
||||
{
|
||||
name_hash().erase(name_hash().find(this));
|
||||
props::remove(this);
|
||||
}
|
||||
|
||||
private:
|
||||
//pstring m_name;
|
||||
static std::unordered_map<const object_t *, pstring> &name_hash()
|
||||
{
|
||||
static std::unordered_map<const object_t *, pstring> lhash;
|
||||
return lhash;
|
||||
}
|
||||
};
|
||||
|
||||
struct netlist_ref
|
||||
@ -1405,7 +1428,7 @@ namespace netlist
|
||||
}
|
||||
|
||||
/* sole use is to manage lifetime of family objects */
|
||||
std::vector<std::pair<pstring, plib::unique_ptr<logic_family_desc_t>>> m_family_cache;
|
||||
std::unordered_map<pstring, plib::unique_ptr<logic_family_desc_t>> m_family_cache;
|
||||
|
||||
setup_t &setup() NL_NOEXCEPT { return *m_setup; }
|
||||
const setup_t &setup() const NL_NOEXCEPT { return *m_setup; }
|
||||
|
@ -964,9 +964,9 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model)
|
||||
if (m_models.value_str(model, "TYPE") == "CD4XXX")
|
||||
return family_CD4XXX();
|
||||
|
||||
for (auto & e : m_nlstate.m_family_cache)
|
||||
if (e.first == model)
|
||||
return e.second.get();
|
||||
auto it = m_nlstate.m_family_cache.find(model);
|
||||
if (it != m_nlstate.m_family_cache.end())
|
||||
return it->second.get();
|
||||
|
||||
auto ret = plib::make_unique<logic_family_std_proxy_t>();
|
||||
|
||||
@ -980,7 +980,7 @@ const logic_family_desc_t *setup_t::family_from_model(const pstring &model)
|
||||
|
||||
auto retp = ret.get();
|
||||
|
||||
m_nlstate.m_family_cache.emplace_back(model, std::move(ret));
|
||||
m_nlstate.m_family_cache.emplace(model, std::move(ret));
|
||||
|
||||
return retp;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user