From f34830aa37fc5c2ff22bac7a3dee62cb1eddee96 Mon Sep 17 00:00:00 2001 From: quininer Date: Tue, 23 Feb 2021 11:16:46 +0800 Subject: [PATCH 1/2] Update scopeguard.rs 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. --- src/scopeguard.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scopeguard.rs b/src/scopeguard.rs index 32c9694372..46dd679edd 100644 --- a/src/scopeguard.rs +++ b/src/scopeguard.rs @@ -42,7 +42,7 @@ impl Drop for ScopeGuard where F: FnMut(&mut T), { - #[cfg_attr(feature = "inline-more", inline)] + #[inline] fn drop(&mut self) { (self.dropfn)(&mut self.value) } From 1ae6dc0e7e8100d43d269b656156064c1807a280 Mon Sep 17 00:00:00 2001 From: quininer Date: Tue, 23 Feb 2021 14:20:26 +0800 Subject: [PATCH 2/2] more inline --- src/scopeguard.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/scopeguard.rs b/src/scopeguard.rs index 46dd679edd..4e9bf045ad 100644 --- a/src/scopeguard.rs +++ b/src/scopeguard.rs @@ -9,7 +9,7 @@ where value: T, } -#[cfg_attr(feature = "inline-more", inline)] +#[inline] pub fn guard(value: T, dropfn: F) -> ScopeGuard where F: FnMut(&mut T), @@ -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 } @@ -32,7 +32,7 @@ impl DerefMut for ScopeGuard where F: FnMut(&mut T), { - #[cfg_attr(feature = "inline-more", inline)] + #[inline] fn deref_mut(&mut self) -> &mut T { &mut self.value }