Skip to content

Commit 16a11ac

Browse files
committed
Merge pull request #111358 from Ivorforce/no-variant-hasher
Remove `VariantHasher` and `VariantComparator` in favour of specialising `HashMapHasherDefault` and `HashMapComparatorDefault`.
2 parents 3e1af9a + d2ee378 commit 16a11ac

File tree

12 files changed

+24
-37
lines changed

12 files changed

+24
-37
lines changed

core/variant/dictionary.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ STATIC_ASSERT_INCOMPLETE_TYPE(class, String);
4747
struct DictionaryPrivate {
4848
SafeRefCount refcount;
4949
Variant *read_only = nullptr; // If enabled, a pointer is used to a temporary value that is used to return read-only values.
50-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator> variant_map;
50+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator> variant_map;
5151
ContainerTypeValidate typed_key;
5252
ContainerTypeValidate typed_value;
5353
Variant *typed_fallback = nullptr; // Allows a typed dictionary to return dummy values when attempting an invalid access.
@@ -143,7 +143,7 @@ const Variant *Dictionary::getptr(const Variant &p_key) const {
143143
if (unlikely(!_p->typed_key.validate(key, "getptr"))) {
144144
return nullptr;
145145
}
146-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
146+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
147147
if (!E) {
148148
return nullptr;
149149
}
@@ -156,7 +156,7 @@ Variant *Dictionary::getptr(const Variant &p_key) {
156156
if (unlikely(!_p->typed_key.validate(key, "getptr"))) {
157157
return nullptr;
158158
}
159-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::Iterator E(_p->variant_map.find(key));
159+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::Iterator E(_p->variant_map.find(key));
160160
if (!E) {
161161
return nullptr;
162162
}
@@ -171,7 +171,7 @@ Variant *Dictionary::getptr(const Variant &p_key) {
171171
Variant Dictionary::get_valid(const Variant &p_key) const {
172172
Variant key = p_key;
173173
ERR_FAIL_COND_V(!_p->typed_key.validate(key, "get_valid"), Variant());
174-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
174+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
175175

176176
if (!E) {
177177
return Variant();
@@ -280,7 +280,7 @@ bool Dictionary::recursive_equal(const Dictionary &p_dictionary, int recursion_c
280280
}
281281
recursion_count++;
282282
for (const KeyValue<Variant, Variant> &this_E : _p->variant_map) {
283-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator other_E(p_dictionary._p->variant_map.find(this_E.key));
283+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator other_E(p_dictionary._p->variant_map.find(this_E.key));
284284
if (!other_E || !this_E.value.hash_compare(other_E->value, recursion_count, false)) {
285285
return false;
286286
}
@@ -438,7 +438,7 @@ void Dictionary::assign(const Dictionary &p_dictionary) {
438438
}
439439

440440
int size = p_dictionary._p->variant_map.size();
441-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator> variant_map = HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>(size);
441+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator> variant_map = HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>(size);
442442

443443
Vector<Variant> key_array;
444444
key_array.resize(size);
@@ -571,7 +571,7 @@ const Variant *Dictionary::next(const Variant *p_key) const {
571571
}
572572
Variant key = *p_key;
573573
ERR_FAIL_COND_V(!_p->typed_key.validate(key, "next"), nullptr);
574-
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::Iterator E = _p->variant_map.find(key);
574+
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::Iterator E = _p->variant_map.find(key);
575575

576576
if (!E) {
577577
return nullptr;

core/variant/dictionary.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct ContainerType;
4242
struct ContainerTypeValidate;
4343
struct DictionaryPrivate;
4444
struct StringLikeVariantComparator;
45-
struct VariantHasher;
4645

4746
class Dictionary {
4847
mutable DictionaryPrivate *_p;
@@ -51,7 +50,7 @@ class Dictionary {
5150
void _unref() const;
5251

5352
public:
54-
using ConstIterator = HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator;
53+
using ConstIterator = HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator;
5554

5655
ConstIterator begin() const;
5756
ConstIterator end() const;

core/variant/variant.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -884,12 +884,9 @@ Vector<Variant> varray(VarArgs... p_args) {
884884
return Vector<Variant>{ p_args... };
885885
}
886886

887-
struct VariantHasher {
888-
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
889-
};
890-
891-
struct VariantComparator {
892-
static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
887+
template <>
888+
struct HashMapComparatorDefault<Variant> {
889+
static bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
893890
};
894891

895892
struct StringLikeVariantComparator {

modules/csg/csg_shape.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,6 @@ class CSGShape3D : public GeometryInstance3D {
8282

8383
Ref<ArrayMesh> root_mesh;
8484

85-
struct Vector3Hasher {
86-
_ALWAYS_INLINE_ uint32_t hash(const Vector3 &p_vec3) const {
87-
uint32_t h = hash_murmur3_one_float(p_vec3.x);
88-
h = hash_murmur3_one_float(p_vec3.y, h);
89-
h = hash_murmur3_one_float(p_vec3.z, h);
90-
return h;
91-
}
92-
};
93-
9485
struct ShapeUpdateSurface {
9586
Vector<Vector3> vertices;
9687
Vector<Vector3> normals;

modules/gdscript/gdscript_analyzer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3833,7 +3833,7 @@ void GDScriptAnalyzer::reduce_cast(GDScriptParser::CastNode *p_cast) {
38333833
}
38343834

38353835
void GDScriptAnalyzer::reduce_dictionary(GDScriptParser::DictionaryNode *p_dictionary) {
3836-
HashMap<Variant, GDScriptParser::ExpressionNode *, VariantHasher, StringLikeVariantComparator> elements;
3836+
HashMap<Variant, GDScriptParser::ExpressionNode *, HashMapHasherDefault, StringLikeVariantComparator> elements;
38373837

38383838
for (int i = 0; i < p_dictionary->elements.size(); i++) {
38393839
const GDScriptParser::DictionaryNode::Pair &element = p_dictionary->elements[i];

modules/gdscript/gdscript_byte_codegen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class GDScriptByteCodeGenerator : public GDScriptCodeGenerator {
104104
List<int> temp_stack;
105105
#endif
106106

107-
HashMap<Variant, int, VariantHasher, VariantComparator> constant_map;
107+
HashMap<Variant, int> constant_map;
108108
RBMap<StringName, int> name_map;
109109
#ifdef TOOLS_ENABLED
110110
Vector<StringName> named_globals;

modules/gdscript/gdscript_tokenizer_buffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include "core/io/compression.h"
3434
#include "core/io/marshalls.h"
3535

36-
int GDScriptTokenizerBuffer::_token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t, VariantHasher, VariantComparator> &r_constants_map) {
36+
int GDScriptTokenizerBuffer::_token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t> &r_constants_map) {
3737
int pos = p_start;
3838

3939
int token_type = p_token.type & TOKEN_MASK;
@@ -239,7 +239,7 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer)
239239

240240
Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code, CompressMode p_compress_mode) {
241241
HashMap<StringName, uint32_t> identifier_map;
242-
HashMap<Variant, uint32_t, VariantHasher, VariantComparator> constant_map;
242+
HashMap<Variant, uint32_t> constant_map;
243243
Vector<uint8_t> token_buffer;
244244
HashMap<uint32_t, uint32_t> token_lines;
245245
HashMap<uint32_t, uint32_t> token_columns;

modules/gdscript/gdscript_tokenizer_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class GDScriptTokenizerBuffer : public GDScriptTokenizer {
6363
HashMap<int, CommentData> dummy;
6464
#endif // TOOLS_ENABLED
6565

66-
static int _token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t, VariantHasher, VariantComparator> &r_constants_map);
66+
static int _token_to_binary(const Token &p_token, Vector<uint8_t> &r_buffer, int p_start, HashMap<StringName, uint32_t> &r_identifiers_map, HashMap<Variant, uint32_t> &r_constants_map);
6767
Token _binary_to_token(const uint8_t *p_buffer);
6868

6969
public:

modules/text_server_adv/text_server_adv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class TextServerAdvanced : public TextServerExtension {
535535
Rect2 rect;
536536
double baseline = 0;
537537
};
538-
HashMap<Variant, EmbeddedObject, VariantHasher, VariantComparator> objects;
538+
HashMap<Variant, EmbeddedObject> objects;
539539

540540
/* Shaped data */
541541
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.

modules/text_server_fb/text_server_fb.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class TextServerFallback : public TextServerExtension {
458458
Rect2 rect;
459459
double baseline = 0;
460460
};
461-
HashMap<Variant, EmbeddedObject, VariantHasher, VariantComparator> objects;
461+
HashMap<Variant, EmbeddedObject> objects;
462462

463463
/* Shaped data */
464464
TextServer::Direction para_direction = DIRECTION_LTR; // Detected text direction.

0 commit comments

Comments
 (0)