-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Query::get_many
should not check for duplicates
#17724
Conversation
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.
Code looks good and I like the test! Strange functionality though. Why would anyone want this?
I think the advantage of if let Ok([player_data, enemy_data]) = query.get_many([player_id, enemy_id]) |
Yeah, but wouldn't you always want to check for duplicates? Like having ([player_id, player_id]) would be weird even if you can't alter the player data cause it's read-only. |
I think the goal there is just performance. Doing the check isn't free. We need it for mutable data for soundness, but for read-only data we can skip it. But I haven't actually used this method myself, so I may not be the best person to justify it :). |
yoki doki makes sense |
Objective
Restore the behavior of
Query::get_many
prior to #15858.When passed duplicate
Entity
s,get_many
is supposed to return results for all of them, since read-only queries don't alias. However, #15858 merged the implementation withget_many_mut
and caused it to returnQueryEntityError::AliasedMutability
.Solution
Introduce a new
Query::get_many_readonly
method that consumes theQuery
likeget_many_inner
, but that is constrained toD: ReadOnlyQueryData
so that it can skip the aliasing check. ImplementQuery::get_many
in terms of that new method. Add a test, and a comment explaining why it doesn't match the pattern of the other&self
methods.