Skip to content

Commit

Permalink
Always inline layout validation and pointer cast code to optimize out…
Browse files Browse the repository at this point in the history
… panics in (#1997) (#2013)

`validate_cast_and_convert_metadata`.

If `try_cast_into` and `validate_cast_and_convert_metadata` are not
inlined, then the compiler will include a panic in `validate_cast_and_convert_metadata`.

If these functions are inlined, then the panic can be optimized out.

Co-authored-by: Carl Lundin <[email protected]>
  • Loading branch information
joshlf and clundin25 authored Nov 4, 2024
1 parent 255babe commit c72fcbf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ impl DstLayout {
/// rely on `validate_cast_and_convert_metadata` panicking in any particular
/// condition, even if `debug_assertions` are enabled.
#[allow(unused)]
#[inline(always)]
pub(crate) const fn validate_cast_and_convert_metadata(
&self,
addr: usize,
Expand Down
1 change: 1 addition & 0 deletions src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ mod _casts {
/// - If this is a prefix cast, `ptr` has the same address as `self`.
/// - If this is a suffix cast, `remainder` has the same address as
/// `self`.
#[inline(always)]
pub(crate) fn try_cast_into<U, R>(
self,
cast_type: CastType,
Expand Down

0 comments on commit c72fcbf

Please sign in to comment.