Skip to content

Commit a7116ad

Browse files
authored
Add #[inline] attribute to a few more methods (#334, #317)
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 explicitly doesn't add the attribute to the methods of `Error`, since those are almost never called in hot code paths.
1 parent 7aaa55c commit a7116ad

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
@@ -69,6 +69,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
6969
([#298](https://github.com/JelteF/derive_more/pull/298))
7070
- Add `TryFrom` derive for enums to convert from their discriminant.
7171
([#300](https://github.com/JelteF/derive_more/pull/300))
72+
- `#[inline]` attributes to `IsVariant` and `Debug` implementations.
73+
([#334](https://github.com/JelteF/derive_more/pull/334)
7274

7375
### Changed
7476

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]` here on purpose, since this is almost never part
41+
// of a 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]` here on purpose, since this is almost never part
52+
// of a 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)