Skip to content

Commit 4979a1b

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 4979a1b

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
8080
- Upgrade to `syn` 2.0.
8181
- The `Error` derive now works in nightly `no_std` environments when enabling
8282
`#![feature(error_in_core)]`.
83+
- `#[inline]` attributes are added to `IsVariant` and `Debug` implementations.
84+
([#334](https://github.com/JelteF/derive_more/pull/334)
8385

8486
### Fixed
8587

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)