Skip to content

Commit

Permalink
Auto merge of rust-lang#103556 - clubby789:specialize-option-partial-…
Browse files Browse the repository at this point in the history
…eq, r=scottmcm

Manually implement PartialEq for Option<T> and specialize non-nullable types

This PR manually implements `PartialEq` and `StructuralPartialEq` for `Option`, which seems to produce slightly better codegen than the automatically derived implementation.

It also allows specializing on the `core::num::NonZero*` and `core::ptr::NonNull` types, taking advantage of the niche optimization by transmuting the `Option<T>` to `T` to be compared directly, which can be done in just two instructions.

A comparison of the original, new and specialized code generation is available [here](https://godbolt.org/z/dE4jxdYsa).
  • Loading branch information
bors committed Nov 26, 2022
2 parents 85a496a + d3d1005 commit 8feb79e
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 8feb79e

Please sign in to comment.