Skip to content

Commit fbe9f18

Browse files
authored
Inline zerocopy layout helpers (#3481)
* Inline zerocopy layout helpers * Inline zerocopy layout helpers
1 parent ed09d09 commit fbe9f18

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(zerocopy_inline_always, inline(always))]
7475
const fn try_to_nonzero_elem_size(&self) -> Option<SizeInfo<NonZeroUsize>> {
7576
Some(match *self {
7677
SizeInfo::Sized { size } => SizeInfo::Sized { size },

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(zerocopy_inline_always, inline(always))]
153154
pub(crate) const fn padding_needed_for(len: usize, align: NonZeroUsize) -> usize {
154155
#[cfg(kani)]
155156
#[kani::proof_for_contract(padding_needed_for)]
@@ -251,6 +252,7 @@ pub(crate) const fn round_down_to_next_multiple_of_alignment(
251252
n & mask
252253
}
253254

255+
#[cfg_attr(zerocopy_inline_always, inline(always))]
254256
pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
255257
if a.get() < b.get() {
256258
b
@@ -259,6 +261,7 @@ pub(crate) const fn max(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
259261
}
260262
}
261263

264+
#[cfg_attr(zerocopy_inline_always, inline(always))]
262265
pub(crate) const fn min(a: NonZeroUsize, b: NonZeroUsize) -> NonZeroUsize {
263266
if a.get() > b.get() {
264267
b

0 commit comments

Comments
 (0)