diff options
author | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-09-27 15:56:54 +0200 |
---|---|---|
committer | A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> | 2024-10-18 08:47:05 +0200 |
commit | 79f654ced5525515091c99a8d23dccb9c2a09b35 (patch) | |
tree | 8f17f2ef6cf280af8c8df6039f123a1182a54169 /core/variant/variant.h | |
parent | 04692d83cb8f61002f18ea1d954df8c558ee84f7 (diff) | |
download | redot-engine-79f654ced5525515091c99a8d23dccb9c2a09b35.tar.gz |
[Core] Fix sorting of `Dictionary` keys
`StringName` keys were sorted as `StringName` which is unstable.
Diffstat (limited to 'core/variant/variant.h')
-rw-r--r-- | core/variant/variant.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/core/variant/variant.h b/core/variant/variant.h index c76b849abd..3b1924e8ea 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -854,6 +854,19 @@ struct StringLikeVariantComparator { static bool compare(const Variant &p_lhs, const Variant &p_rhs); }; +struct StringLikeVariantOrder { + static _ALWAYS_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) { + if (p_lhs.is_string() && p_rhs.is_string()) { + return p_lhs.operator String() < p_rhs.operator String(); + } + return p_lhs < p_rhs; + } + + _ALWAYS_INLINE_ bool operator()(const Variant &p_lhs, const Variant &p_rhs) const { + return compare(p_lhs, p_rhs); + } +}; + Variant::ObjData &Variant::_get_obj() { return *reinterpret_cast<ObjData *>(&_data._mem[0]); } |