From c72fcbf4db8a287599534e854aef8b2c18e891ca Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Mon, 4 Nov 2024 08:52:34 -0800 Subject: [PATCH] Always inline layout validation and pointer cast code to optimize out 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 <108372512+clundin25@users.noreply.github.com> --- src/layout.rs | 1 + src/pointer/ptr.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/layout.rs b/src/layout.rs index 5aaf102f8a..e73fef409b 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -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, diff --git a/src/pointer/ptr.rs b/src/pointer/ptr.rs index b476d1428f..c134139032 100644 --- a/src/pointer/ptr.rs +++ b/src/pointer/ptr.rs @@ -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( self, cast_type: CastType,