-
Notifications
You must be signed in to change notification settings - Fork 12.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
Migrate lib's &Option<T>
into Option<&T>
#130962
Conversation
This comment has been minimized.
This comment has been minimized.
&Option<T>
into Option<&T>
&Option<T>
into Option<&T>
Migrate compiler's `&Option<T>` into `Option<&T>` Similar to rust-lang#130962 but for the compiler. Trying out my new lint rust-lang/rust-clippy#13336 - according to the [video](https://www.youtube.com/watch?v=6c7pZYP_iIE), this could lead to some performance and memory optimizations.
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.
I don't think any of these instances will matter for performance, but it seems fine as a bit of polish.
I think part of my earlier comment slipped notice, regarding
|
good catch @cuviper, fixed |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Josh Stone <cuviper@gmail.com>
Co-authored-by: Josh Stone <cuviper@gmail.com>
no idea what has caused last CI failure, rebasing on main. |
The job Click to see the possible cause of the failure (guessed by this bot)
|
@cuviper is |
It's not you -- see #131434 |
@bors r+ rollup |
Rollup of 7 pull requests Successful merges: - rust-lang#124874 (intrinsics fmuladdf{32,64}: expose llvm.fmuladd.* semantics) - rust-lang#130962 (Migrate lib's `&Option<T>` into `Option<&T>`) - rust-lang#131289 (stabilize duration_consts_float) - rust-lang#131310 (Support clobber_abi in MSP430 inline assembly) - rust-lang#131546 (Make unused_parens's suggestion considering expr's attributes.) - rust-lang#131565 (Remove deprecation note in the `non_local_definitions` lint) - rust-lang#131576 (Flatten redundant test module `run_make_support::diff::tests::tests`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 7 pull requests Successful merges: - rust-lang#124874 (intrinsics fmuladdf{32,64}: expose llvm.fmuladd.* semantics) - rust-lang#130962 (Migrate lib's `&Option<T>` into `Option<&T>`) - rust-lang#131289 (stabilize duration_consts_float) - rust-lang#131310 (Support clobber_abi in MSP430 inline assembly) - rust-lang#131546 (Make unused_parens's suggestion considering expr's attributes.) - rust-lang#131565 (Remove deprecation note in the `non_local_definitions` lint) - rust-lang#131576 (Flatten redundant test module `run_make_support::diff::tests::tests`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#130962 - nyurik:opts-libs, r=cuviper Migrate lib's `&Option<T>` into `Option<&T>` Trying out my new lint rust-lang/rust-clippy#13336 - according to the [video](https://www.youtube.com/watch?v=6c7pZYP_iIE), this could lead to some performance and memory optimizations. Basic thoughts expressed in the video that seem to make sense: * `&Option<T>` in an API breaks encapsulation: * caller must own T and move it into an Option to call with it * if returned, the owner must store it as Option<T> internally in order to return it * Performance is subject to compiler optimization, but at the basics, `&Option<T>` points to memory that has `presence` flag + value, whereas `Option<&T>` by specification is always optimized to a single pointer.
Trying out my new lint rust-lang/rust-clippy#13336 - according to the video, this could lead to some performance and memory optimizations.
Basic thoughts expressed in the video that seem to make sense:
&Option<T>
in an API breaks encapsulation:&Option<T>
points to memory that haspresence
flag + value, whereasOption<&T>
by specification is always optimized to a single pointer.