Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4778df5

Browse files
jsgfemilio
authored andcommittedApr 1, 2024
Make all the flexarray helpers inline
The conversions between fixed and dynamically sized forms are essentially type-level transforms which should have trivial implementations in terms of generated code, so there's no reason not to make them inline.
1 parent 0478a39 commit 4778df5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
 

‎bindgen-tests/tests/expectations/tests/flexarray.rs

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bindgen/codegen/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,13 +2747,15 @@ impl CompInfo {
27472747

27482748
(
27492749
quote! {
2750+
#[inline]
27502751
pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) {
27512752
unsafe {
27522753
let (ptr, len) = (self as *const Self).to_raw_parts();
27532754
(&*(ptr as *const #sized_ty_for_impl), len)
27542755
}
27552756
}
27562757

2758+
#[inline]
27572759
pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) {
27582760
unsafe {
27592761
let (ptr, len) = (self as *mut Self).to_raw_parts();
@@ -2773,6 +2775,7 @@ impl CompInfo {
27732775
/// Convert a mutable sized prefix to an unsized structure with the given length.
27742776
///
27752777
/// SAFETY: Underlying storage is initialized up to at least `len` elements.
2778+
#[inline]
27762779
pub unsafe fn flex_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl {
27772780
// SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`.
27782781
#flex_ref_mut_inner
@@ -2782,6 +2785,7 @@ impl CompInfo {
27822785
///
27832786
/// NOTE: lifetime of returned reference is not tied to any underlying storage.
27842787
/// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements.
2788+
#[inline]
27852789
pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl {
27862790
#flex_ptr_inner
27872791
}
@@ -2793,6 +2797,7 @@ impl CompInfo {
27932797
///
27942798
/// NOTE: lifetime of returned reference is not tied to any underlying storage.
27952799
/// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements.
2800+
#[inline]
27962801
pub unsafe fn flex_ptr_mut<'unbounded>(
27972802
ptr: *mut Self,
27982803
len: usize,

0 commit comments

Comments
 (0)
Please sign in to comment.