Skip to content

Commit

Permalink
Inline WakerRef functions (#2626)
Browse files Browse the repository at this point in the history
Those functions are trivial and non-generic. It's necessary
to use `#[inline]` to enable cross-crate inlining for
non-generic functions when LTO is disabled.
  • Loading branch information
KamilaBorowska authored and taiki-e committed Aug 14, 2022
1 parent 0f4d34c commit 4145d59
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions futures-task/src/waker_ref.rs
Expand Up @@ -18,6 +18,7 @@ pub struct WakerRef<'a> {

impl<'a> WakerRef<'a> {
/// Create a new [`WakerRef`] from a [`Waker`] reference.
#[inline]
pub fn new(waker: &'a Waker) -> Self {
// copy the underlying (raw) waker without calling a clone,
// as we won't call Waker::drop either.
Expand All @@ -31,6 +32,7 @@ impl<'a> WakerRef<'a> {
/// an unsafe way (that will be valid only for a lifetime to be determined
/// by the caller), and the [`Waker`] doesn't need to or must not be
/// destroyed.
#[inline]
pub fn new_unowned(waker: ManuallyDrop<Waker>) -> Self {
Self { waker, _marker: PhantomData }
}
Expand All @@ -39,6 +41,7 @@ impl<'a> WakerRef<'a> {
impl Deref for WakerRef<'_> {
type Target = Waker;

#[inline]
fn deref(&self) -> &Waker {
&self.waker
}
Expand Down

0 comments on commit 4145d59

Please sign in to comment.