Skip to content

Commit 695b214

Browse files
committed
Add #[inline] attribute to a few more methods
To be clear the `#[inline]` does not hint that inlining is beneficial, but it does give the compiler the option to inline if the compiler things it would be beneficial. This starts adding the `#[inline]` attribute to: 1. `IsVariant`: it's expected that this is often beneficial since its body is tiny. 2. `Debug`: This is to stay in line with the `std` implementation of the `Debug` derive. rust-lang/rust#117727 It also explicitely doesn't add the attribute to the methods of `Error`, since those are almost never called in hot code paths. Fixes #317
1 parent 7aaa55c commit 695b214

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

impl/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub fn expand(
3737
};
3838

3939
let source = source.map(|source| {
40+
// not using #[inline] on purpose since this is almost never part of a
41+
// hot codepath
4042
quote! {
4143
fn source(&self) -> Option<&(dyn ::derive_more::Error + 'static)> {
4244
use ::derive_more::__private::AsDynError;
@@ -46,6 +48,8 @@ pub fn expand(
4648
});
4749

4850
let provide = provide.map(|provide| {
51+
// not using #[inline] on purpose since this is almost never part of a
52+
// hot codepath
4953
quote! {
5054
fn provide<'_request>(&'_request self, request: &mut ::derive_more::core::error::Request<'_request>) {
5155
#provide

impl/src/fmt/debug.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub fn expand(input: &syn::DeriveInput, _: &str) -> syn::Result<TokenStream> {
4747
Ok(quote! {
4848
#[automatically_derived]
4949
impl #impl_gens ::derive_more::Debug for #ident #ty_gens #where_clause {
50+
#[inline]
5051
fn fmt(
5152
&self, __derive_more_f: &mut ::derive_more::core::fmt::Formatter<'_>
5253
) -> ::derive_more::core::fmt::Result {

impl/src/is_variant.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn expand(input: &DeriveInput, trait_name: &'static str) -> Result<TokenStre
4444
#[doc = "Returns `true` if this value is of type `"]
4545
#[doc = #variant_name]
4646
#[doc = "`. Returns `false` otherwise"]
47+
#[inline]
4748
pub const fn #fn_name(&self) -> bool {
4849
match self {
4950
#enum_name ::#variant_ident #data_pattern => true,

0 commit comments

Comments
 (0)