1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 18:53:28 +01:00

Replace ppu_module_manager Function Static with Class Static variable (static module map) (#8669)

* Replace ppu_module_manager Function Static with Class Static

Makes for a slightly 'cleaner' interface in my opinion, may also assist with adding thread read/write concurrency support in future if ever required (have left that out of this commit to match existing function).

Very slight performance improvements were seen in representative testing.
https://quick-bench.com/q/GMbgeNc-mZc21aqOKCofnbzPZvg

I didn't investigate whether static initialisation of the static_modules might actually be possible here, perhaps there's a way to do a constexpr / consteval of this.

* Fix up for old style cast syntax..

* Fixups from PR comments

Plus remove spurious type_traits include (from me) not picked up in previous PR

* Remove old code

* Update rpcs3/Emu/Cell/PPUModule.h

Co-authored-by: Eladash <elad3356p@gmail.com>

* Fix naming of static variable

Co-authored-by: Eladash <elad3356p@gmail.com>
This commit is contained in:
Bevan Weiss 2020-08-06 20:34:08 +10:00 committed by GitHub
parent eee5e812f7
commit ada6db2df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 15 deletions

View File

@ -61,21 +61,14 @@ ppu_static_module::ppu_static_module(const char* name)
ppu_module_manager::register_module(this); ppu_module_manager::register_module(this);
} }
std::unordered_map<std::string, ppu_static_module*>& ppu_module_manager::access()
{
static std::unordered_map<std::string, ppu_static_module*> map;
return map;
}
void ppu_module_manager::register_module(ppu_static_module* _module) void ppu_module_manager::register_module(ppu_static_module* _module)
{ {
access().emplace(_module->name, _module); ppu_module_manager::s_module_map.emplace(_module->name, _module);
} }
ppu_static_function& ppu_module_manager::access_static_function(const char* _module, u32 fnid) ppu_static_function& ppu_module_manager::access_static_function(const char* _module, u32 fnid)
{ {
auto& res = access().at(_module)->functions[fnid]; auto& res = ppu_module_manager::s_module_map.at(_module)->functions[fnid];
if (res.name) if (res.name)
{ {
@ -87,7 +80,7 @@ ppu_static_function& ppu_module_manager::access_static_function(const char* _mod
ppu_static_variable& ppu_module_manager::access_static_variable(const char* _module, u32 vnid) ppu_static_variable& ppu_module_manager::access_static_variable(const char* _module, u32 vnid)
{ {
auto& res = access().at(_module)->variables[vnid]; auto& res = ppu_module_manager::s_module_map.at(_module)->variables[vnid];
if (res.name) if (res.name)
{ {
@ -99,7 +92,7 @@ ppu_static_variable& ppu_module_manager::access_static_variable(const char* _mod
const ppu_static_module* ppu_module_manager::get_module(const std::string& name) const ppu_static_module* ppu_module_manager::get_module(const std::string& name)
{ {
const auto& map = access(); const auto& map = ppu_module_manager::s_module_map;
const auto found = map.find(name); const auto found = map.find(name);
return found != map.end() ? found->second : nullptr; return found != map.end() ? found->second : nullptr;
} }

View File

@ -101,8 +101,6 @@ class ppu_module_manager final
{ {
friend class ppu_static_module; friend class ppu_static_module;
static std::unordered_map<std::string, ppu_static_module*>& access();
static void register_module(ppu_static_module*); static void register_module(ppu_static_module*);
static ppu_static_function& access_static_function(const char* _module, u32 fnid); static ppu_static_function& access_static_function(const char* _module, u32 fnid);
@ -161,9 +159,10 @@ public:
return info; return info;
} }
static const auto& get() // We need this to deal with the enumeration over all ppu_static_modules that happens in ppu_initialize_modules
static const std::unordered_map<std::string, ppu_static_module*>& get()
{ {
return access(); return s_module_map;
} }
static const ppu_static_module cellAdec; static const ppu_static_module cellAdec;
@ -273,6 +272,9 @@ public:
static const ppu_static_module sys_libc; static const ppu_static_module sys_libc;
static const ppu_static_module sys_lv2dbg; static const ppu_static_module sys_lv2dbg;
static const ppu_static_module static_hle; static const ppu_static_module static_hle;
private:
inline static std::unordered_map<std::string, ppu_static_module*> s_module_map;
}; };
template <auto* Func> template <auto* Func>