Skip to content

Commit

Permalink
Pre-emptively store all types in lookup map
Browse files Browse the repository at this point in the history
  • Loading branch information
kagenocookie authored Nov 10, 2024
1 parent 2dcca30 commit 26ac3e6
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions shared/sdk/RETypeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,33 @@ reframework::InvokeRet invoke_object_func(::REManagedObject* obj, std::string_vi
}

sdk::RETypeDefinition* RETypeDB::find_type(std::string_view name) const {
static bool map_populated = false;

{
std::shared_lock _{ g_tdb_type_mtx };

if (auto it = g_tdb_type_map.find(name.data()); it != g_tdb_type_map.end()) {
return it->second;
}

if (map_populated) {
return nullptr;
}
}

for (uint32_t i = 0; i < this->numTypes; ++i) {
auto t = get_type(i);
{
std::unique_lock _{ g_tdb_type_mtx };

map_populated = true;

if (t->get_full_name() == name) {
std::unique_lock _{ g_tdb_type_mtx };
for (uint32_t i = 0; i < this->numTypes; ++i) {
auto t = get_type(i);

g_tdb_type_map[name.data()] = t;
return g_tdb_type_map[name.data()];
g_tdb_type_map[t->get_full_name()] = t;
}
}

std::unique_lock _{ g_tdb_type_mtx };
return g_tdb_type_map[name.data()];
return this->find_type(name);
}

sdk::RETypeDefinition* RETypeDB::find_type_by_fqn(uint32_t fqn) const {
Expand Down Expand Up @@ -1152,4 +1158,4 @@ std::vector<const char*> REMethodDefinition::get_param_names() const {
return out;
#endif
}
} // namespace sdk
} // namespace sdk

0 comments on commit 26ac3e6

Please sign in to comment.