47
47
#include < list>
48
48
#include < mutex>
49
49
#include < set>
50
- #include < string>
51
- #include < unordered_map>
52
50
#include < vector>
53
51
54
- // Needed to use StringName as key in `std::unordered_map`
55
- template <>
56
- struct std ::hash<godot::StringName> {
57
- std::size_t operator ()(godot::StringName const &s) const noexcept {
58
- return s.hash ();
59
- }
60
- };
52
+ #include < godot_cpp/templates/a_hash_map.hpp>
61
53
62
54
namespace godot {
63
55
@@ -95,9 +87,9 @@ class ClassDB {
95
87
StringName name;
96
88
StringName parent_name;
97
89
GDExtensionInitializationLevel level = GDEXTENSION_INITIALIZATION_SCENE;
98
- std::unordered_map <StringName, MethodBind *> method_map;
90
+ AHashMap <StringName, MethodBind *> method_map;
99
91
std::set<StringName> signal_names;
100
- std::unordered_map <StringName, VirtualMethod> virtual_methods;
92
+ AHashMap <StringName, VirtualMethod> virtual_methods;
101
93
std::set<StringName> property_names;
102
94
std::set<StringName> constant_names;
103
95
// Pointer to the parent custom class, if any. Will be null if the parent class is a Godot class.
@@ -106,11 +98,11 @@ class ClassDB {
106
98
107
99
private:
108
100
// This may only contain custom classes, not Godot classes
109
- static std::unordered_map <StringName, ClassInfo> classes;
110
- static std::unordered_map <StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks;
101
+ static AHashMap <StringName, ClassInfo> classes;
102
+ static AHashMap <StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks;
111
103
// Used to remember the custom class registration order.
112
104
static std::vector<StringName> class_register_order;
113
- static std::unordered_map <StringName, Object *> engine_singletons;
105
+ static AHashMap <StringName, Object *> engine_singletons;
114
106
static std::mutex engine_singletons_mutex;
115
107
116
108
static MethodBind *bind_methodfi (uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount);
@@ -171,9 +163,9 @@ class ClassDB {
171
163
172
164
static void _register_engine_singleton (const StringName &p_class_name, Object *p_singleton) {
173
165
std::lock_guard<std::mutex> lock (engine_singletons_mutex);
174
- std::unordered_map <StringName, Object *>::const_iterator i = engine_singletons.find (p_class_name);
166
+ AHashMap <StringName, Object *>::ConstIterator i = engine_singletons.find (p_class_name);
175
167
if (i != engine_singletons.end ()) {
176
- ERR_FAIL_COND ((*i).second != p_singleton);
168
+ ERR_FAIL_COND ((*i).value != p_singleton);
177
169
return ;
178
170
}
179
171
engine_singletons[p_class_name] = p_singleton;
@@ -243,10 +235,10 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) {
243
235
cl.name = T::get_class_static ();
244
236
cl.parent_name = T::get_parent_class_static ();
245
237
cl.level = current_level;
246
- std::unordered_map <StringName, ClassInfo>::iterator parent_it = classes.find (cl.parent_name );
238
+ AHashMap <StringName, ClassInfo>::Iterator parent_it = classes.find (cl.parent_name );
247
239
if (parent_it != classes.end ()) {
248
240
// Assign parent if it is also a custom class
249
- cl.parent_ptr = &parent_it->second ;
241
+ cl.parent_ptr = &parent_it->value ;
250
242
}
251
243
classes[cl.name ] = cl;
252
244
class_register_order.push_back (cl.name );
@@ -340,13 +332,13 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p
340
332
341
333
StringName instance_type = bind->get_instance_class ();
342
334
343
- std::unordered_map <StringName, ClassInfo>::iterator type_it = classes.find (instance_type);
335
+ AHashMap <StringName, ClassInfo>::Iterator type_it = classes.find (instance_type);
344
336
if (type_it == classes.end ()) {
345
337
memdelete (bind);
346
338
ERR_FAIL_V_MSG (nullptr , String (" Class '{0}' doesn't exist." ).format (Array::make (instance_type)));
347
339
}
348
340
349
- ClassInfo &type = type_it->second ;
341
+ ClassInfo &type = type_it->value ;
350
342
351
343
if (type.method_map .find (p_name) != type.method_map .end ()) {
352
344
memdelete (bind);
0 commit comments