mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
Remove VariantHasher and VariantComparator in favour of specializing HashMapHasherDefault and HashMapComparatorDefault.
This commit is contained in:
parent
c01c7b800d
commit
d2ee378d1c
12 changed files with 24 additions and 37 deletions
|
|
@ -45,7 +45,7 @@ STATIC_ASSERT_INCOMPLETE_TYPE(class, Array);
|
|||
struct DictionaryPrivate {
|
||||
SafeRefCount refcount;
|
||||
Variant *read_only = nullptr; // If enabled, a pointer is used to a temporary value that is used to return read-only values.
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator> variant_map;
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator> variant_map;
|
||||
ContainerTypeValidate typed_key;
|
||||
ContainerTypeValidate typed_value;
|
||||
Variant *typed_fallback = nullptr; // Allows a typed dictionary to return dummy values when attempting an invalid access.
|
||||
|
|
@ -139,7 +139,7 @@ const Variant *Dictionary::getptr(const Variant &p_key) const {
|
|||
if (unlikely(!_p->typed_key.validate(key, "getptr"))) {
|
||||
return nullptr;
|
||||
}
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
|
||||
if (!E) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -152,7 +152,7 @@ Variant *Dictionary::getptr(const Variant &p_key) {
|
|||
if (unlikely(!_p->typed_key.validate(key, "getptr"))) {
|
||||
return nullptr;
|
||||
}
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::Iterator E(_p->variant_map.find(key));
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::Iterator E(_p->variant_map.find(key));
|
||||
if (!E) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -167,7 +167,7 @@ Variant *Dictionary::getptr(const Variant &p_key) {
|
|||
Variant Dictionary::get_valid(const Variant &p_key) const {
|
||||
Variant key = p_key;
|
||||
ERR_FAIL_COND_V(!_p->typed_key.validate(key, "get_valid"), Variant());
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator E(_p->variant_map.find(key));
|
||||
|
||||
if (!E) {
|
||||
return Variant();
|
||||
|
|
@ -276,7 +276,7 @@ bool Dictionary::recursive_equal(const Dictionary &p_dictionary, int recursion_c
|
|||
}
|
||||
recursion_count++;
|
||||
for (const KeyValue<Variant, Variant> &this_E : _p->variant_map) {
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator other_E(p_dictionary._p->variant_map.find(this_E.key));
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator other_E(p_dictionary._p->variant_map.find(this_E.key));
|
||||
if (!other_E || !this_E.value.hash_compare(other_E->value, recursion_count, false)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -434,7 +434,7 @@ void Dictionary::assign(const Dictionary &p_dictionary) {
|
|||
}
|
||||
|
||||
int size = p_dictionary._p->variant_map.size();
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator> variant_map = HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>(size);
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator> variant_map = HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>(size);
|
||||
|
||||
Vector<Variant> key_array;
|
||||
key_array.resize(size);
|
||||
|
|
@ -567,7 +567,7 @@ const Variant *Dictionary::next(const Variant *p_key) const {
|
|||
}
|
||||
Variant key = *p_key;
|
||||
ERR_FAIL_COND_V(!_p->typed_key.validate(key, "next"), nullptr);
|
||||
HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::Iterator E = _p->variant_map.find(key);
|
||||
HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::Iterator E = _p->variant_map.find(key);
|
||||
|
||||
if (!E) {
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@ struct ContainerType;
|
|||
struct ContainerTypeValidate;
|
||||
struct DictionaryPrivate;
|
||||
struct StringLikeVariantComparator;
|
||||
struct VariantHasher;
|
||||
|
||||
class Dictionary {
|
||||
mutable DictionaryPrivate *_p;
|
||||
|
|
@ -51,7 +50,7 @@ class Dictionary {
|
|||
void _unref() const;
|
||||
|
||||
public:
|
||||
using ConstIterator = HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator;
|
||||
using ConstIterator = HashMap<Variant, Variant, HashMapHasherDefault, StringLikeVariantComparator>::ConstIterator;
|
||||
|
||||
ConstIterator begin() const;
|
||||
ConstIterator end() const;
|
||||
|
|
|
|||
|
|
@ -884,12 +884,9 @@ Vector<Variant> varray(VarArgs... p_args) {
|
|||
return Vector<Variant>{ p_args... };
|
||||
}
|
||||
|
||||
struct VariantHasher {
|
||||
static _FORCE_INLINE_ uint32_t hash(const Variant &p_variant) { return p_variant.hash(); }
|
||||
};
|
||||
|
||||
struct VariantComparator {
|
||||
static _FORCE_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
|
||||
template <>
|
||||
struct HashMapComparatorDefault<Variant> {
|
||||
static bool compare(const Variant &p_lhs, const Variant &p_rhs) { return p_lhs.hash_compare(p_rhs); }
|
||||
};
|
||||
|
||||
struct StringLikeVariantComparator {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue