Skip to content

Commit 875c3bd

Browse files
committed
Replace unordered_map with HashMap
1 parent 24d79ab commit 875c3bd

File tree

3 files changed

+776
-50
lines changed

3 files changed

+776
-50
lines changed

include/godot_cpp/core/class_db.hpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,9 @@
4747
#include <list>
4848
#include <mutex>
4949
#include <set>
50-
#include <string>
51-
#include <unordered_map>
5250
#include <vector>
5351

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>
6153

6254
namespace godot {
6355

@@ -95,9 +87,9 @@ class ClassDB {
9587
StringName name;
9688
StringName parent_name;
9789
GDExtensionInitializationLevel level = GDEXTENSION_INITIALIZATION_SCENE;
98-
std::unordered_map<StringName, MethodBind *> method_map;
90+
AHashMap<StringName, MethodBind *> method_map;
9991
std::set<StringName> signal_names;
100-
std::unordered_map<StringName, VirtualMethod> virtual_methods;
92+
AHashMap<StringName, VirtualMethod> virtual_methods;
10193
std::set<StringName> property_names;
10294
std::set<StringName> constant_names;
10395
// 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 {
10698

10799
private:
108100
// 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;
111103
// Used to remember the custom class registration order.
112104
static std::vector<StringName> class_register_order;
113-
static std::unordered_map<StringName, Object *> engine_singletons;
105+
static AHashMap<StringName, Object *> engine_singletons;
114106
static std::mutex engine_singletons_mutex;
115107

116108
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 {
171163

172164
static void _register_engine_singleton(const StringName &p_class_name, Object *p_singleton) {
173165
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);
175167
if (i != engine_singletons.end()) {
176-
ERR_FAIL_COND((*i).second != p_singleton);
168+
ERR_FAIL_COND((*i).value != p_singleton);
177169
return;
178170
}
179171
engine_singletons[p_class_name] = p_singleton;
@@ -243,10 +235,10 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) {
243235
cl.name = T::get_class_static();
244236
cl.parent_name = T::get_parent_class_static();
245237
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);
247239
if (parent_it != classes.end()) {
248240
// Assign parent if it is also a custom class
249-
cl.parent_ptr = &parent_it->second;
241+
cl.parent_ptr = &parent_it->value;
250242
}
251243
classes[cl.name] = cl;
252244
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
340332

341333
StringName instance_type = bind->get_instance_class();
342334

343-
std::unordered_map<StringName, ClassInfo>::iterator type_it = classes.find(instance_type);
335+
AHashMap<StringName, ClassInfo>::Iterator type_it = classes.find(instance_type);
344336
if (type_it == classes.end()) {
345337
memdelete(bind);
346338
ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(Array::make(instance_type)));
347339
}
348340

349-
ClassInfo &type = type_it->second;
341+
ClassInfo &type = type_it->value;
350342

351343
if (type.method_map.find(p_name) != type.method_map.end()) {
352344
memdelete(bind);

0 commit comments

Comments
 (0)