From e419aaf3025f1c82b8e1a69fa33356b896dd968a Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 9 Apr 2025 09:54:18 +0000 Subject: [PATCH] refactor(ast_tools): move limit for inlining to a const in `Visit` generator (#10291) Pure refactor. `Visit` generator adds `#[inline]` attr to visitor methods containing 5 or less statements. Make this limit a `const`, rather than having it inline in multiple places. --- tasks/ast_tools/src/generators/visit.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/tasks/ast_tools/src/generators/visit.rs b/tasks/ast_tools/src/generators/visit.rs index a1181361f268b..cd89bd539715c 100644 --- a/tasks/ast_tools/src/generators/visit.rs +++ b/tasks/ast_tools/src/generators/visit.rs @@ -17,6 +17,10 @@ use crate::{ use super::{AttrLocation, AttrPart, AttrPositions, attr_positions, define_generator}; +/// Visitors with less than this number of fields/variants will be marked `#[inline]`. +// TODO: Is this the ideal value? +const INLINE_LIMIT: usize = 5; + /// Generator for `Visit` and `VisitMut` traits. pub struct VisitGenerator; @@ -422,10 +426,9 @@ impl VisitBuilder<'_> { field_visits_mut.extend(leave_scope); } - // `#[inline]` if there are 5 or less fields visited - // TODO: Is this ideal? + // `#[inline]` if there are `INLINE_LIMIT` or less fields visited let maybe_inline_attr = - if field_visits_count <= 5 { quote!( #[inline] ) } else { quote!() }; + if field_visits_count <= INLINE_LIMIT { quote!( #[inline] ) } else { quote!() }; self.walk_fns.extend(quote! { ///@@line_break @@ -592,9 +595,9 @@ impl VisitBuilder<'_> { quote!() }; - // `#[inline]` if there are 5 or less match cases - // TODO: Is this ideal? - let maybe_inline_attr = if match_arm_count <= 5 { quote!( #[inline] ) } else { quote!() }; + // `#[inline]` if there are `INLINE_LIMIT` or less fields visited + let maybe_inline_attr = + if match_arm_count <= INLINE_LIMIT { quote!( #[inline] ) } else { quote!() }; self.walk_fns.extend(quote! { ///@@line_break