Skip to content

Commit 0f03af0

Browse files
committed
Use ThinVec to shrink LazyAttrTokenStreamInner.
1 parent 3203473 commit 0f03af0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

compiler/rustc_ast/src/tokenstream.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use rustc_data_structures::sync;
2323
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
2424
use rustc_serialize::{Decodable, Encodable};
2525
use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
26+
use thin_vec::ThinVec;
2627

2728
use crate::ast::AttrStyle;
2829
use crate::ast_traits::{HasAttrs, HasTokens};
@@ -122,7 +123,7 @@ impl LazyAttrTokenStream {
122123
cursor_snapshot: TokenCursor,
123124
num_calls: u32,
124125
break_last_token: u32,
125-
node_replacements: Box<[NodeReplacement]>,
126+
node_replacements: ThinVec<NodeReplacement>,
126127
) -> LazyAttrTokenStream {
127128
LazyAttrTokenStream(Arc::new(LazyAttrTokenStreamInner::Pending {
128129
start_token,
@@ -219,7 +220,8 @@ pub struct LazyAttrTokenStreamImpl {
219220
pub cursor_snapshot: TokenCursor,
220221
pub num_calls: u32,
221222
pub break_last_token: u32,
222-
pub node_replacements: Box<[NodeReplacement]>,
223+
/// This vec is almost alway empty.
224+
pub node_replacements: ThinVec<NodeReplacement>,
223225
}
224226

225227
enum LazyAttrTokenStreamInner {
@@ -242,7 +244,7 @@ enum LazyAttrTokenStreamInner {
242244
cursor_snapshot: TokenCursor,
243245
num_calls: u32,
244246
break_last_token: u32,
245-
node_replacements: Box<[NodeReplacement]>,
247+
node_replacements: ThinVec<NodeReplacement>,
246248
},
247249
}
248250

@@ -1043,7 +1045,7 @@ mod size_asserts {
10431045
static_assert_size!(AttrTokenStream, 8);
10441046
static_assert_size!(AttrTokenTree, 32);
10451047
static_assert_size!(LazyAttrTokenStream, 8);
1046-
static_assert_size!(LazyAttrTokenStreamInner, 96);
1048+
static_assert_size!(LazyAttrTokenStreamInner, 88);
10471049
static_assert_size!(Option<LazyAttrTokenStream>, 8); // must be small, used in many AST nodes
10481050
static_assert_size!(TokenStream, 8);
10491051
static_assert_size!(TokenTree, 32);

compiler/rustc_parse/src/parser/attr_wrapper.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
1010
use rustc_errors::PResult;
1111
use rustc_session::parse::ParseSess;
1212
use rustc_span::{DUMMY_SP, sym};
13+
use thin_vec::ThinVec;
1314

1415
use super::{Capturing, ForceCollect, Parser, Trailing};
1516

@@ -294,10 +295,10 @@ impl<'a> Parser<'a> {
294295

295296
// This is hot enough for `deep-vector` that checking the conditions for an empty iterator
296297
// is measurably faster than actually executing the iterator.
297-
let node_replacements: Box<[_]> = if parser_replacements_start == parser_replacements_end
298+
let node_replacements = if parser_replacements_start == parser_replacements_end
298299
&& inner_attr_parser_replacements.is_empty()
299300
{
300-
Box::new([])
301+
ThinVec::new()
301302
} else {
302303
// Grab any replace ranges that occur *inside* the current AST node. Convert them
303304
// from `ParserRange` form to `NodeRange` form. We will perform the actual

0 commit comments

Comments
 (0)