Skip to content

Commit

Permalink
Auto merge of rust-lang#242 - quininer:patch-2, r=Amanieu
Browse files Browse the repository at this point in the history
always inline `ScopeGuard::drop`

I accidentally discovered that some minor changes in a production project will cause a lot of size increase and some performance regression. After comparison, I found a lot of `ScopeGuard::drop` symbols appeared in the poorer version.

I suspect this is because the compiler missed some inline. for `ScopeGuard`, it should always be beneficial to inline it.
  • Loading branch information
bors committed Feb 23, 2021
2 parents de77272 + 1ae6dc0 commit b19c14a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/scopeguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ where
value: T,
}

#[cfg_attr(feature = "inline-more", inline)]
#[inline]
pub fn guard<T, F>(value: T, dropfn: F) -> ScopeGuard<T, F>
where
F: FnMut(&mut T),
Expand All @@ -22,7 +22,7 @@ where
F: FnMut(&mut T),
{
type Target = T;
#[cfg_attr(feature = "inline-more", inline)]
#[inline]
fn deref(&self) -> &T {
&self.value
}
Expand All @@ -32,7 +32,7 @@ impl<T, F> DerefMut for ScopeGuard<T, F>
where
F: FnMut(&mut T),
{
#[cfg_attr(feature = "inline-more", inline)]
#[inline]
fn deref_mut(&mut self) -> &mut T {
&mut self.value
}
Expand All @@ -42,7 +42,7 @@ impl<T, F> Drop for ScopeGuard<T, F>
where
F: FnMut(&mut T),
{
#[cfg_attr(feature = "inline-more", inline)]
#[inline]
fn drop(&mut self) {
(self.dropfn)(&mut self.value)
}
Expand Down

0 comments on commit b19c14a

Please sign in to comment.