Skip to content

Commit 01ed9dd

Browse files
committed
Use ThinVec in a few more AST types.
1 parent 23007fc commit 01ed9dd

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/modules.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::ast;
66
use rustc_ast::visit::Visitor;
77
use rustc_span::symbol::{self, sym, Symbol};
88
use rustc_span::Span;
9+
use thin_vec::ThinVec;
910
use thiserror::Error;
1011

1112
use crate::attr::MetaVisitor;
@@ -25,7 +26,7 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
2526
#[derive(Debug, Clone)]
2627
pub(crate) struct Module<'a> {
2728
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
28-
pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
29+
pub(crate) items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
2930
inner_attr: ast::AttrVec,
3031
pub(crate) span: Span,
3132
}
@@ -34,7 +35,7 @@ impl<'a> Module<'a> {
3435
pub(crate) fn new(
3536
mod_span: Span,
3637
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
37-
mod_items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
38+
mod_items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
3839
mod_attrs: Cow<'a, ast::AttrVec>,
3940
) -> Self {
4041
let inner_attr = mod_attrs
@@ -157,7 +158,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
157158
Module::new(
158159
module_item.item.span,
159160
Some(Cow::Owned(sub_mod_kind.clone())),
160-
Cow::Owned(vec![]),
161+
Cow::Owned(ThinVec::new()),
161162
Cow::Owned(ast::AttrVec::new()),
162163
),
163164
)?;
@@ -169,7 +170,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
169170
/// Visit modules defined inside macro calls.
170171
fn visit_mod_outside_ast(
171172
&mut self,
172-
items: Vec<rustc_ast::ptr::P<ast::Item>>,
173+
items: ThinVec<rustc_ast::ptr::P<ast::Item>>,
173174
) -> Result<(), ModuleResolutionError> {
174175
for item in items {
175176
if is_cfg_if(&item) {
@@ -184,7 +185,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
184185
Module::new(
185186
span,
186187
Some(Cow::Owned(sub_mod_kind.clone())),
187-
Cow::Owned(vec![]),
188+
Cow::Owned(ThinVec::new()),
188189
Cow::Owned(ast::AttrVec::new()),
189190
),
190191
)?;
@@ -210,7 +211,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
210211
Module::new(
211212
span,
212213
Some(Cow::Borrowed(sub_mod_kind)),
213-
Cow::Owned(vec![]),
214+
Cow::Owned(ThinVec::new()),
214215
Cow::Borrowed(&item.attrs),
215216
),
216217
)?;

src/parse/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::{ast, ptr};
66
use rustc_errors::Diagnostic;
77
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
88
use rustc_span::{sym, Span};
9+
use thin_vec::ThinVec;
910

1011
use crate::attr::first_attr_value_str_by_name;
1112
use crate::parse::session::ParseSess;
@@ -109,7 +110,7 @@ impl<'a> Parser<'a> {
109110
sess: &'a ParseSess,
110111
path: &Path,
111112
span: Span,
112-
) -> Result<(ast::AttrVec, Vec<ptr::P<ast::Item>>, Span), ParserError> {
113+
) -> Result<(ast::AttrVec, ThinVec<ptr::P<ast::Item>>, Span), ParserError> {
113114
let result = catch_unwind(AssertUnwindSafe(|| {
114115
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
115116
match parser.parse_mod(&TokenKind::Eof) {

0 commit comments

Comments
 (0)