about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-04-29 12:05:38 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-04-30 07:12:09 +1000
commit880e6f716d741b4ef827d48e66c45c7887f82aa2 (patch)
treee77b0985e121c4727d7d31f03c9323462332c3a3
parent298c56f4ba604d3c7025a44fe7bfe1134d6b56d6 (diff)
downloadrust-880e6f716d741b4ef827d48e66c45c7887f82aa2.tar.gz
rust-880e6f716d741b4ef827d48e66c45c7887f82aa2.zip
Use `ThinVec` to shrink `LazyAttrTokenStreamInner`.
-rw-r--r--compiler/rustc_ast/src/tokenstream.rs7
-rw-r--r--compiler/rustc_parse/src/parser/attr_wrapper.rs5
2 files changed, 7 insertions, 5 deletions
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs
index 4f352e20da2..636c26bcde0 100644
--- a/compiler/rustc_ast/src/tokenstream.rs
+++ b/compiler/rustc_ast/src/tokenstream.rs
@@ -23,6 +23,7 @@ use rustc_data_structures::sync;
 use rustc_macros::{Decodable, Encodable, HashStable_Generic};
 use rustc_serialize::{Decodable, Encodable};
 use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
+use thin_vec::ThinVec;
 
 use crate::ast::AttrStyle;
 use crate::ast_traits::{HasAttrs, HasTokens};
@@ -122,7 +123,7 @@ impl LazyAttrTokenStream {
         cursor_snapshot: TokenCursor,
         num_calls: u32,
         break_last_token: u32,
-        node_replacements: Box<[NodeReplacement]>,
+        node_replacements: ThinVec<NodeReplacement>,
     ) -> LazyAttrTokenStream {
         LazyAttrTokenStream(Arc::new(LazyAttrTokenStreamInner::Pending {
             start_token,
@@ -233,7 +234,7 @@ enum LazyAttrTokenStreamInner {
         cursor_snapshot: TokenCursor,
         num_calls: u32,
         break_last_token: u32,
-        node_replacements: Box<[NodeReplacement]>,
+        node_replacements: ThinVec<NodeReplacement>,
     },
 }
 
@@ -1034,7 +1035,7 @@ mod size_asserts {
     static_assert_size!(AttrTokenStream, 8);
     static_assert_size!(AttrTokenTree, 32);
     static_assert_size!(LazyAttrTokenStream, 8);
-    static_assert_size!(LazyAttrTokenStreamInner, 96);
+    static_assert_size!(LazyAttrTokenStreamInner, 88);
     static_assert_size!(Option<LazyAttrTokenStream>, 8); // must be small, used in many AST nodes
     static_assert_size!(TokenStream, 8);
     static_assert_size!(TokenTree, 32);
diff --git a/compiler/rustc_parse/src/parser/attr_wrapper.rs b/compiler/rustc_parse/src/parser/attr_wrapper.rs
index 835226a64af..44fdf146f9c 100644
--- a/compiler/rustc_parse/src/parser/attr_wrapper.rs
+++ b/compiler/rustc_parse/src/parser/attr_wrapper.rs
@@ -10,6 +10,7 @@ use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::PResult;
 use rustc_session::parse::ParseSess;
 use rustc_span::{DUMMY_SP, sym};
+use thin_vec::ThinVec;
 
 use super::{Capturing, ForceCollect, Parser, Trailing};
 
@@ -294,10 +295,10 @@ impl<'a> Parser<'a> {
 
         // This is hot enough for `deep-vector` that checking the conditions for an empty iterator
         // is measurably faster than actually executing the iterator.
-        let node_replacements: Box<[_]> = if parser_replacements_start == parser_replacements_end
+        let node_replacements = if parser_replacements_start == parser_replacements_end
             && inner_attr_parser_replacements.is_empty()
         {
-            Box::new([])
+            ThinVec::new()
         } else {
             // Grab any replace ranges that occur *inside* the current AST node. Convert them
             // from `ParserRange` form to `NodeRange` form. We will perform the actual