@@ -15,9 +15,19 @@ constexpr auto METADATA_TAG = 0xB324ABC;
15
15
16
16
struct ProxyCCNode ;
17
17
18
+ static uint64_t fnv1aHash (char const * str) {
19
+ uint64_t hash = 0xcbf29ce484222325 ;
20
+ while (*str) {
21
+ hash ^= *str++;
22
+ hash *= 0x100000001b3 ;
23
+ }
24
+ return hash;
25
+ }
26
+
18
27
class GeodeNodeMetadata final : public cocos2d::CCObject {
19
28
private:
20
- std::unordered_map<std::string, FieldContainer*> m_classFieldContainers;
29
+ // for performance reasons, this key is the hash of the class name
30
+ std::unordered_map<uint64_t , FieldContainer*> m_classFieldContainers;
21
31
std::string m_id = " " ;
22
32
Ref<Layout> m_layout = nullptr ;
23
33
Ref<LayoutOptions> m_layoutOptions = nullptr ;
@@ -63,10 +73,14 @@ class GeodeNodeMetadata final : public cocos2d::CCObject {
63
73
}
64
74
65
75
FieldContainer* getFieldContainer (char const * forClass) {
66
- if (!m_classFieldContainers.count (forClass)) {
67
- m_classFieldContainers[forClass] = new FieldContainer ();
76
+ auto hash = fnv1aHash (forClass);
77
+
78
+ auto & container = m_classFieldContainers[hash];
79
+ if (!container) {
80
+ container = new FieldContainer ();
68
81
}
69
- return m_classFieldContainers[forClass];
82
+
83
+ return container;
70
84
}
71
85
};
72
86
@@ -78,7 +92,7 @@ struct ProxyCCNode : Modify<ProxyCCNode, CCNode> {
78
92
return asNode->getUserObject (" " );
79
93
}
80
94
else {
81
- // apparently this function is the same as
95
+ // apparently this function is the same as
82
96
// CCDirector::getNextScene so yeah
83
97
return m_pUserObject;
84
98
}
@@ -224,7 +238,7 @@ class NodeQuery final {
224
238
}
225
239
collectedID.push_back (c);
226
240
}
227
- // Any other character is syntax error due to needing to reserve
241
+ // Any other character is syntax error due to needing to reserve
228
242
// stuff for possible future features
229
243
else {
230
244
return Err (" Unexpected character '{}' at index {}" , c, i);
0 commit comments