Skip to content

Commit

Permalink
Rollup merge of #130962 - nyurik:opts-libs, r=cuviper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgross35 authored Oct 12, 2024
2 parents d207a9c + 0dd9a5f commit 2ea2c97
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 2ea2c97

Please sign in to comment.