Skip to content

Commit fc33db3

Browse files
EFanZhEFanZh
authored andcommitted
Inline some functions
1 parent efc831a commit fc33db3

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

library/alloc/src/raw_rc/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl RefCounts {
214214
///
215215
/// - `value_ptr` must point to a value object (can be uninitialized or dropped) that lives in a
216216
/// reference-counted allocation.
217+
#[inline]
217218
unsafe fn ref_counts_ptr_from_value_ptr(value_ptr: NonNull<()>) -> NonNull<RefCounts> {
218219
// SAFETY: Caller guarantees `value_ptr` point to the value inside some reference counted, our
219220
// implementation guarantees the `RefCounts` object has offset of `size_of::<RefCounts>()` to
@@ -228,6 +229,7 @@ unsafe fn ref_counts_ptr_from_value_ptr(value_ptr: NonNull<()>) -> NonNull<RefCo
228229
///
229230
/// - `value_ptr` must point to a value object (can be uninitialized or dropped) that lives in a
230231
/// reference-counted allocation.
232+
#[inline]
231233
unsafe fn strong_count_ptr_from_value_ptr(value_ptr: NonNull<()>) -> NonNull<UnsafeCell<usize>> {
232234
let ref_counts_ptr = unsafe { ref_counts_ptr_from_value_ptr(value_ptr) };
233235

@@ -241,6 +243,7 @@ unsafe fn strong_count_ptr_from_value_ptr(value_ptr: NonNull<()>) -> NonNull<Uns
241243
///
242244
/// - `value_ptr` must point to a value object (can be uninitialized or dropped) that lives in a
243245
/// reference-counted allocation.
246+
#[inline]
244247
unsafe fn weak_count_ptr_from_value_ptr(value_ptr: NonNull<()>) -> NonNull<UnsafeCell<usize>> {
245248
let ref_counts_ptr = unsafe { ref_counts_ptr_from_value_ptr(value_ptr) };
246249

@@ -415,6 +418,7 @@ where
415418
/// Allocates a reference-counted memory chunk for storing a value according to `rc_layout`, then
416419
/// initialize the value with `f`. If `f` panics, the allocated memory will be deallocated.
417420
#[cfg(not(no_global_oom_handling))]
421+
#[inline]
418422
fn allocate_with_in<A, F, const STRONG_COUNT: usize>(
419423
alloc: &A,
420424
rc_layout: RcLayout,
@@ -456,6 +460,7 @@ where
456460
/// described by `rc_layout`. `f` will be called with a pointer that points the value storage to
457461
/// initialize the allocated memory. If `f` panics, the allocated memory will be deallocated.
458462
#[cfg(not(no_global_oom_handling))]
463+
#[inline]
459464
fn allocate_with<A, F, const STRONG_COUNT: usize>(rc_layout: RcLayout, f: F) -> (NonNull<()>, A)
460465
where
461466
A: Allocator + Default,
@@ -475,6 +480,7 @@ where
475480
/// - Memory pointed to by `src_ptr` has enough data to read for filling the value in an allocation
476481
/// that is described by `rc_layout`.
477482
#[cfg(not(no_global_oom_handling))]
483+
#[inline]
478484
unsafe fn allocate_with_bytes_in<A, const STRONG_COUNT: usize>(
479485
src_ptr: NonNull<()>,
480486
alloc: &A,
@@ -499,6 +505,7 @@ where
499505

500506
/// Allocates a chunk of reference-counted memory with a value that is copied from `value`.
501507
#[cfg(not(no_global_oom_handling))]
508+
#[inline]
502509
fn allocate_with_value_in<T, A, const STRONG_COUNT: usize>(src: &T, alloc: &A) -> NonNull<T>
503510
where
504511
T: ?Sized,

library/alloc/src/raw_rc/raw_rc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::vec::Vec;
3232

3333
/// Decrements strong reference count in a reference-counted allocation with a value object that is
3434
/// pointed to by `value_ptr`.
35+
#[inline]
3536
unsafe fn decrement_strong_ref_count<R>(value_ptr: NonNull<()>) -> bool
3637
where
3738
R: RcOps,
@@ -41,13 +42,15 @@ where
4142

4243
/// Increments strong reference count in a reference-counted allocation with a value object that is
4344
/// pointed to by `value_ptr`.
45+
#[inline]
4446
unsafe fn increment_strong_ref_count<R>(value_ptr: NonNull<()>)
4547
where
4648
R: RcOps,
4749
{
4850
unsafe { R::increment_ref_count(super::strong_count_ptr_from_value_ptr(value_ptr).as_ref()) }
4951
}
5052

53+
#[inline]
5154
unsafe fn is_unique<R>(value_ptr: NonNull<()>) -> bool
5255
where
5356
R: RcOps,

library/alloc/src/raw_rc/raw_weak.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn is_dangling(value_ptr: NonNull<()>) -> bool {
3535

3636
/// Decrements weak reference count in a reference-counted allocation with a value object that is
3737
/// pointed to by `value_ptr`.
38+
#[inline]
3839
unsafe fn decrement_weak_ref_count<R>(value_ptr: NonNull<()>) -> bool
3940
where
4041
R: RcOps,
@@ -44,6 +45,7 @@ where
4445

4546
/// Increments weak reference count in a reference-counted allocation with a value object that is
4647
/// pointed to by `value_ptr`.
48+
#[inline]
4749
unsafe fn increment_weak_ref_count<R>(value_ptr: NonNull<()>)
4850
where
4951
R: RcOps,

0 commit comments

Comments
 (0)