-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Fix sorting of Dictionary
keys
#97542
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -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) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This static method isn't technically needed with the alternative solution (or when using I will look at adding such static methods to other comparators to aid in using them for such cases |
||||
if (p_lhs.is_string() && p_rhs.is_string()) { | ||||
return p_lhs.operator String() < p_rhs.operator String(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allocating memory, filling it, then doing a comparison on the copy before dropping it immediately on the floor feels very slapdash. The memory should already be meaningful and available to use for such a comparison. Perhaps this can be reused?: Line 534 in f032af7
edit: I don't trust this line 😆 perhaps I can be assuaged that there are no allocations in the general cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't allocate memory except when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll take it, thank you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But will keep in mind for a future helper allowing comparison with both |
||||
} | ||||
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]); | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that there is already
StringLikeVariantComparator
, I have a minor question. As far as I know, there are three main types of comparators:a == b
). Not suitable for sorting.a < b
ora <= b
).a <=> b
in C++20). Not sure if we use something like this.It would be nice to make sure that we use consistent naming for these types. But that's not directly relevant to the issue, just a note.
struct \w+(Compare|Comparator|Sort|Sorter|Order)\b
matchesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, would have gone with
Compare
if it wasn't already taken, can go forSort
as it is more common it seems, will change when final decision on the solution is takenThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to standardize this I'd change the ones named
Compare
but does equality checks toEq
or similar and the ones comparing order toCompare
(as it seems the most common for those)