Skip to content

Commit d0617bc

Browse files
authored
Pre-emptively store all types in lookup map (#1148)
1 parent 99d0dfb commit d0617bc

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

shared/sdk/RETypeDB.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,33 @@ reframework::InvokeRet invoke_object_func(::REManagedObject* obj, std::string_vi
4646
}
4747

4848
sdk::RETypeDefinition* RETypeDB::find_type(std::string_view name) const {
49+
static bool map_populated = false;
50+
4951
{
5052
std::shared_lock _{ g_tdb_type_mtx };
5153

5254
if (auto it = g_tdb_type_map.find(name.data()); it != g_tdb_type_map.end()) {
5355
return it->second;
5456
}
57+
58+
if (map_populated) {
59+
return nullptr;
60+
}
5561
}
5662

57-
for (uint32_t i = 0; i < this->numTypes; ++i) {
58-
auto t = get_type(i);
63+
{
64+
std::unique_lock _{ g_tdb_type_mtx };
65+
66+
map_populated = true;
5967

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

63-
g_tdb_type_map[name.data()] = t;
64-
return g_tdb_type_map[name.data()];
71+
g_tdb_type_map[t->get_full_name()] = t;
6572
}
6673
}
6774

68-
std::unique_lock _{ g_tdb_type_mtx };
69-
return g_tdb_type_map[name.data()];
75+
return this->find_type(name);
7076
}
7177

7278
sdk::RETypeDefinition* RETypeDB::find_type_by_fqn(uint32_t fqn) const {
@@ -1152,4 +1158,4 @@ std::vector<const char*> REMethodDefinition::get_param_names() const {
11521158
return out;
11531159
#endif
11541160
}
1155-
} // namespace sdk
1161+
} // namespace sdk

0 commit comments

Comments
 (0)