Skip to content

Commit d0d872c

Browse files
committed
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 17d7b13 commit d0d872c

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
@@ -2702,13 +2702,15 @@ impl CompInfo {
27022702

27032703
(
27042704
quote! {
2705+
#[inline]
27052706
pub fn fixed(&self) -> (& #sized_ty_for_impl, usize) {
27062707
unsafe {
27072708
let (ptr, len) = (self as *const Self).to_raw_parts();
27082709
(&*(ptr as *const #sized_ty_for_impl), len)
27092710
}
27102711
}
27112712

2713+
#[inline]
27122714
pub fn fixed_mut(&mut self) -> (&mut #sized_ty_for_impl, usize) {
27132715
unsafe {
27142716
let (ptr, len) = (self as *mut Self).to_raw_parts();
@@ -2728,6 +2730,7 @@ impl CompInfo {
27282730
/// Convert a mutable sized prefix to an unsized structure with the given length.
27292731
///
27302732
/// SAFETY: Underlying storage is initialized up to at least `len` elements.
2733+
#[inline]
27312734
pub unsafe fn flex_ref_mut(&mut self, len: usize) -> &mut #dst_ty_for_impl {
27322735
// SAFETY: Reference is always valid as pointer. Caller is guaranteeing `len`.
27332736
#flex_ref_mut_inner
@@ -2737,6 +2740,7 @@ impl CompInfo {
27372740
///
27382741
/// NOTE: lifetime of returned reference is not tied to any underlying storage.
27392742
/// SAFETY: `ptr` is valid. Underlying storage is fully initialized up to at least `len` elements.
2743+
#[inline]
27402744
pub unsafe fn flex_ptr<'unbounded>(ptr: *const Self, len: usize) -> &'unbounded #dst_ty_for_impl {
27412745
#flex_ptr_inner
27422746
}
@@ -2748,6 +2752,7 @@ impl CompInfo {
27482752
///
27492753
/// NOTE: lifetime of returned reference is not tied to any underlying storage.
27502754
/// SAFETY: `ptr` is valid. Underlying storage has space for at least `len` elements.
2755+
#[inline]
27512756
pub unsafe fn flex_ptr_mut<'unbounded>(
27522757
ptr: *mut Self,
27532758
len: usize,

0 commit comments

Comments
 (0)