Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions tasks/ast_tools/src/generators/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading