Skip to content

Commit 0f7c0bd

Browse files
authored
Add unconditional #[inline] to layout helper functions (#3483)
* Add baseline inline annotations * Gate baseline inline annotations
1 parent fbe9f18 commit 0f7c0bd

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

zerocopy/src/layout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl SizeInfo {
7171
/// Attempts to create a `SizeInfo` from `Self` in which `elem_size` is a
7272
/// `NonZeroUsize`. If `elem_size` is 0, returns `None`.
7373
#[allow(unused)]
74+
#[cfg_attr(not(zerocopy_inline_always), inline)]
7475
#[cfg_attr(zerocopy_inline_always, inline(always))]
7576
const fn try_to_nonzero_elem_size(&self) -> Option<SizeInfo<NonZeroUsize>> {
7677
Some(match *self {

zerocopy/src/util/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub(crate) fn validate_aligned_to<T: AsAddress, U>(t: T) -> Result<(), Alignment
150150
// Ensures that we add the minimum required padding.
151151
kani::ensures(|&p| p < align.get()),
152152
)]
153+
#[cfg_attr(not(zerocopy_inline_always), inline)]
153154
#[cfg_attr(zerocopy_inline_always, inline(always))]
154155
pub(crate) const fn padding_needed_for(len: usize, align: NonZeroUsize) -> usize {
155156
#[cfg(kani)]
@@ -252,6 +253,7 @@ pub(crate) const fn round_down_to_next_multiple_of_alignment(
252253
n & mask
253254
}
254255

256+
#[cfg_attr(not(zerocopy_inline_always), inline)]
255257
#[cfg_attr(zerocopy_inline_always, inline(always))]
256258
pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
257259
if a.get() < b.get() {
@@ -261,6 +263,7 @@ pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
261263
}
262264
}
263265

266+
#[cfg_attr(not(zerocopy_inline_always), inline)]
264267
#[cfg_attr(zerocopy_inline_always, inline(always))]
265268
pub(crate) const fn min(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
266269
if a.get() > b.get() {

0 commit comments

Comments
 (0)