diff --git a/regex-automata/src/util/pool.rs b/regex-automata/src/util/pool.rs index c03d7b013..95afa4a0d 100644 --- a/regex-automata/src/util/pool.rs +++ b/regex-automata/src/util/pool.rs @@ -177,6 +177,7 @@ impl T> Pool { /// the value to go back into the pool) and then calling get again is /// *not* guaranteed to return the same value received in the first `get` /// call. + #[inline] pub fn get(&self) -> PoolGuard<'_, T, F> { PoolGuard(self.0.get()) } @@ -200,6 +201,7 @@ impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F> { /// This circumvents the guard's `Drop` implementation. This can be useful /// in circumstances where the automatic `Drop` results in poorer codegen, /// such as calling non-inlined functions. + #[inline] pub fn put(this: PoolGuard<'_, T, F>) { inner::PoolGuard::put(this.0); } @@ -208,12 +210,14 @@ impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F> { impl<'a, T: Send, F: Fn() -> T> core::ops::Deref for PoolGuard<'a, T, F> { type Target = T; + #[inline] fn deref(&self) -> &T { self.0.value() } } impl<'a, T: Send, F: Fn() -> T> core::ops::DerefMut for PoolGuard<'a, T, F> { + #[inline] fn deref_mut(&mut self) -> &mut T { self.0.value_mut() } @@ -469,6 +473,7 @@ mod inner { impl T> Pool { /// Get a value from the pool. This may block if another thread is also /// attempting to retrieve a value from the pool. + #[inline] pub(super) fn get(&self) -> PoolGuard<'_, T, F> { // Our fast path checks if the caller is the thread that "owns" // this pool. Or stated differently, whether it is the first thread @@ -562,6 +567,7 @@ mod inner { /// Puts a value back into the pool. Callers don't need to call this. /// Once the guard that's returned by 'get' is dropped, it is put back /// into the pool automatically. + #[inline] fn put_value(&self, value: Box) { let caller = THREAD_ID.with(|id| *id); let stack_id = caller % self.stacks.len(); @@ -587,11 +593,13 @@ mod inner { } /// Create a guard that represents the special owned T. + #[inline] fn guard_owned(&self, caller: usize) -> PoolGuard<'_, T, F> { PoolGuard { pool: self, value: Err(caller), discard: false } } /// Create a guard that contains a value from the pool's stack. + #[inline] fn guard_stack(&self, value: Box) -> PoolGuard<'_, T, F> { PoolGuard { pool: self, value: Ok(value), discard: false } } @@ -599,6 +607,7 @@ mod inner { /// Create a guard that contains a value from the pool's stack with an /// instruction to throw away the value instead of putting it back /// into the pool. + #[inline] fn guard_stack_transient(&self, value: Box) -> PoolGuard<'_, T, F> { PoolGuard { pool: self, value: Ok(value), discard: true } } @@ -633,6 +642,7 @@ mod inner { impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F> { /// Return the underlying value. + #[inline] pub(super) fn value(&self) -> &T { match self.value { Ok(ref v) => &**v, @@ -657,6 +667,7 @@ mod inner { } /// Return the underlying value as a mutable borrow. + #[inline] pub(super) fn value_mut(&mut self) -> &mut T { match self.value { Ok(ref mut v) => &mut **v, @@ -681,6 +692,7 @@ mod inner { } /// Consumes this guard and puts it back into the pool. + #[inline] pub(super) fn put(this: PoolGuard<'_, T, F>) { // Since this is effectively consuming the guard and putting the // value back into the pool, there's no reason to run its Drop @@ -729,6 +741,7 @@ mod inner { } impl<'a, T: Send, F: Fn() -> T> Drop for PoolGuard<'a, T, F> { + #[inline] fn drop(&mut self) { self.put_imp(); } @@ -806,6 +819,7 @@ mod inner { impl T> Pool { /// Get a value from the pool. This may block if another thread is also /// attempting to retrieve a value from the pool. + #[inline] pub(super) fn get(&self) -> PoolGuard<'_, T, F> { let mut stack = self.stack.lock(); let value = match stack.pop() { @@ -815,6 +829,7 @@ mod inner { PoolGuard { pool: self, value: Some(value) } } + #[inline] fn put(&self, guard: PoolGuard<'_, T, F>) { let mut guard = core::mem::ManuallyDrop::new(guard); if let Some(value) = guard.value.take() { @@ -825,6 +840,7 @@ mod inner { /// Puts a value back into the pool. Callers don't need to call this. /// Once the guard that's returned by 'get' is dropped, it is put back /// into the pool automatically. + #[inline] fn put_value(&self, value: Box) { let mut stack = self.stack.lock(); stack.push(value); @@ -847,16 +863,19 @@ mod inner { impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F> { /// Return the underlying value. + #[inline] pub(super) fn value(&self) -> &T { self.value.as_deref().unwrap() } /// Return the underlying value as a mutable borrow. + #[inline] pub(super) fn value_mut(&mut self) -> &mut T { self.value.as_deref_mut().unwrap() } /// Consumes this guard and puts it back into the pool. + #[inline] pub(super) fn put(this: PoolGuard<'_, T, F>) { // Since this is effectively consuming the guard and putting the // value back into the pool, there's no reason to run its Drop @@ -878,6 +897,7 @@ mod inner { } impl<'a, T: Send, F: Fn() -> T> Drop for PoolGuard<'a, T, F> { + #[inline] fn drop(&mut self) { self.put_imp(); } @@ -931,6 +951,7 @@ mod inner { /// Lock this mutex and return a guard providing exclusive access to /// `T`. This blocks if some other thread has already locked this /// mutex. + #[inline] fn lock(&self) -> MutexGuard<'_, T> { while self .locked @@ -963,18 +984,21 @@ mod inner { impl<'a, T> core::ops::Deref for MutexGuard<'a, T> { type Target = T; + #[inline] fn deref(&self) -> &T { self.data } } impl<'a, T> core::ops::DerefMut for MutexGuard<'a, T> { + #[inline] fn deref_mut(&mut self) -> &mut T { self.data } } impl<'a, T> Drop for MutexGuard<'a, T> { + #[inline] fn drop(&mut self) { // Drop means 'data' is no longer accessible, so we can unlock // the mutex.