1
Fork 0

Use ThinVec in ast::WhereClause.

This commit is contained in:
Nicholas Nethercote 2022-11-22 16:23:25 +11:00
parent dd7aff5cc5
commit 068db466e8
6 changed files with 92 additions and 76 deletions

View file

@ -403,13 +403,13 @@ pub struct WhereClause {
/// if we parsed no predicates (e.g. `struct Foo where {}`).
/// This allows us to pretty-print accurately.
pub has_where_token: bool,
pub predicates: Vec<WherePredicate>,
pub predicates: ThinVec<WherePredicate>,
pub span: Span,
}
impl Default for WhereClause {
fn default() -> WhereClause {
WhereClause { has_where_token: false, predicates: Vec::new(), span: DUMMY_SP }
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }
}
}
@ -3115,15 +3115,15 @@ mod size_asserts {
static_assert_size!(Block, 48);
static_assert_size!(Expr, 72);
static_assert_size!(ExprKind, 40);
static_assert_size!(Fn, 168);
static_assert_size!(Fn, 152);
static_assert_size!(ForeignItem, 96);
static_assert_size!(ForeignItemKind, 24);
static_assert_size!(GenericArg, 24);
static_assert_size!(GenericBound, 56);
static_assert_size!(Generics, 56);
static_assert_size!(Impl, 168);
static_assert_size!(Item, 168);
static_assert_size!(ItemKind, 96);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 152);
static_assert_size!(Item, 152);
static_assert_size!(ItemKind, 80);
static_assert_size!(LitKind, 24);
static_assert_size!(Local, 72);
static_assert_size!(MetaItemLit, 40);

View file

@ -17,10 +17,10 @@ use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::Ident;
use rustc_span::Span;
use smallvec::{smallvec, Array, SmallVec};
use std::ops::DerefMut;
use std::{panic, ptr};
use thin_vec::ThinVec;
pub trait ExpectOne<A: Array> {
fn expect_one(self, err: &'static str) -> A::Item;
@ -335,6 +335,17 @@ where
}
}
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
#[inline]
pub fn visit_thin_vec<T, F>(elems: &mut ThinVec<T>, mut visit_elem: F)
where
F: FnMut(&mut T),
{
for elem in elems {
visit_elem(elem);
}
}
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
#[inline]
pub fn visit_opt<T, F>(opt: &mut Option<T>, mut visit_elem: F)
@ -917,7 +928,7 @@ pub fn noop_visit_generics<T: MutVisitor>(generics: &mut Generics, vis: &mut T)
pub fn noop_visit_where_clause<T: MutVisitor>(wc: &mut WhereClause, vis: &mut T) {
let WhereClause { has_where_token: _, predicates, span } = wc;
visit_vec(predicates, |predicate| vis.visit_where_predicate(predicate));
visit_thin_vec(predicates, |predicate| vis.visit_where_predicate(predicate));
vis.visit_span(span);
}