Skip to content

Commit 698986d

Browse files
perf(profiling): add #[inline] to RefCellExt trait methods
The RefCellExt trait is used at 20+ call sites across the codebase. Add #[inline] attribute to: - try_with_borrow and try_with_borrow_mut in impl block - borrow_or_false and borrow_mut_or_false default methods This allows LLVM to inline these small wrapper functions at call sites, eliminating the trait dispatch overhead in optimized builds.
1 parent 3df3a27 commit 698986d

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

profiling/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,13 +471,15 @@ trait RefCellExt<T> {
471471
where
472472
F: FnOnce(&mut T) -> R;
473473

474+
#[inline]
474475
fn borrow_or_false<F>(&'static self, f: F) -> bool
475476
where
476477
F: FnOnce(&T) -> bool,
477478
{
478479
self.try_with_borrow(f).unwrap_or(false)
479480
}
480481

482+
#[inline]
481483
fn borrow_mut_or_false<F>(&'static self, f: F) -> bool
482484
where
483485
F: FnOnce(&mut T) -> bool,
@@ -487,6 +489,7 @@ trait RefCellExt<T> {
487489
}
488490

489491
impl<T> RefCellExt<T> for LocalKey<RefCell<T>> {
492+
#[inline]
490493
fn try_with_borrow<F, R>(&'static self, f: F) -> Result<R, RefCellExtError>
491494
where
492495
F: FnOnce(&T) -> R,
@@ -496,6 +499,7 @@ impl<T> RefCellExt<T> for LocalKey<RefCell<T>> {
496499
})??)
497500
}
498501

502+
#[inline]
499503
fn try_with_borrow_mut<F, R>(&'static self, f: F) -> Result<R, RefCellExtError>
500504
where
501505
F: FnOnce(&mut T) -> R,

0 commit comments

Comments
 (0)