-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Explicitly deref in float partial_eq #97943
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
Conversation
The current code will not results bug, but it difficult to understand. These code result to call &f32::partial_cmp(), and the performance will be lower than the changed code. I'm not sure why the current code don't use (*self) (*other), if you have some idea, please let me know.
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @kennytm (or someone else) soon. Please see the contribution instructions for more information. |
There isn't an implementation of |
When I debug, the code go to the following implementation. And this for all &T which implement PartialOrd. So f32::partial_cmp call &f32::le() and &f32::ge(). To avoid going here, should change "self" to "*self" and "other" to "*other" impl<A: ?Sized, B: ?Sized> PartialOrd<&B> for &A |
There is such an implementation (docs), but it shouldn't have an impact on performance. Do you have an example of a performance improvement? |
Ah yes, I'd forgotten there was a blanket impl for references. But it's all inlined and optimised away (at least in release mode) so I'm not sure it's really a big problem? That said, I can't see any issue with making this change. |
I have made a comment, I have some problem to describe the issue and the comment correct the description. If using "self", there will call fn which could be avoid. |
In my opinion, this does not make the code clearer but only adds more noise. This should not have any perf impact, as the compiler usually optimizes these calls away. Godbolt confirms this: https://godbolt.org/z/5TazWeees |
Actually, using "*self" will make it easy to understand. I read it for a lot time and at last debug to know what happened. Though there is not issue, I still suggest to change it to make it easy to understand |
For other fn, the "*self " is used, why this different
For other fn, the "*self " is used, why this different. |
With |
I write it because other fn use parantheses, so make them same . |
line 1352, delete parentheses for reviewers asking for it.
self
to *self
, other to *other
@bors r+ rollup |
📌 Commit 9e1e476 has been approved by |
Current PR title is actually bad :-( |
suggestions are welcome :P |
"Explicitly deref in float partial_eq" |
I'm not fully understand reasons for this PR from description and later discussion, maybe |
self
to *self
, other to *other
…askrgr Rollup of 5 pull requests Successful merges: - rust-lang#97904 (Small grammar fix in the compile_error documentation) - rust-lang#97943 (line 1352, change `self` to `*self`, other to `*other`) - rust-lang#97969 (Make -Cpasses= only apply to pre-link optimization) - rust-lang#97990 (Add more eslint checks) - rust-lang#97994 (feat(fix): update some links in `hir.rs`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
@Dylan-DPC why did this get r+'ed? It's arguable if it's an improvement in readability, and nobody from @rust-lang/libs had the chance to review it. I know it was a small PR, but what's the rush to merge it? |
The current code will not results bug, but it difficult to understand. These code result to call &f32::partial_cmp(), and the performance will be lower than the changed code. I'm not sure why the current code don't use (*self) (*other), if you have some idea, please let me know.