File tree 3 files changed +10
-3
lines changed
3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ type bits = u64;
12
12
/// `Tokens` doesn't include whitespace and comments. Main input to the parser.
13
13
///
14
14
/// Struct of arrays internally, but this shouldn't really matter.
15
- #[ derive( Default ) ]
16
15
pub struct Input {
17
16
kind : Vec < SyntaxKind > ,
18
17
joint : Vec < bits > ,
@@ -21,6 +20,14 @@ pub struct Input {
21
20
22
21
/// `pub` impl used by callers to create `Tokens`.
23
22
impl Input {
23
+ #[ inline]
24
+ pub fn with_capacity ( capacity : usize ) -> Self {
25
+ Self {
26
+ kind : Vec :: with_capacity ( capacity) ,
27
+ joint : Vec :: with_capacity ( capacity / size_of :: < bits > ( ) ) ,
28
+ contextual_kind : Vec :: with_capacity ( capacity) ,
29
+ }
30
+ }
24
31
#[ inline]
25
32
pub fn push ( & mut self , kind : SyntaxKind ) {
26
33
self . push_impl ( kind, SyntaxKind :: EOF )
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ pub enum StrStep<'a> {
27
27
impl LexedStr < ' _ > {
28
28
pub fn to_input ( & self , edition : Edition ) -> crate :: Input {
29
29
let _p = tracing:: info_span!( "LexedStr::to_input" ) . entered ( ) ;
30
- let mut res = crate :: Input :: default ( ) ;
30
+ let mut res = crate :: Input :: with_capacity ( self . len ( ) ) ;
31
31
let mut was_joint = false ;
32
32
for i in 0 ..self . len ( ) {
33
33
let kind = self . kind ( i) ;
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ pub fn to_parser_input<Ctx: Copy + fmt::Debug + PartialEq + Eq + Hash>(
12
12
buffer : tt:: TokenTreesView < ' _ , SpanData < Ctx > > ,
13
13
span_to_edition : & mut dyn FnMut ( Ctx ) -> Edition ,
14
14
) -> parser:: Input {
15
- let mut res = parser:: Input :: default ( ) ;
15
+ let mut res = parser:: Input :: with_capacity ( buffer . len ( ) ) ;
16
16
17
17
let mut current = buffer. cursor ( ) ;
18
18
let mut syntax_context_to_edition_cache = FxHashMap :: default ( ) ;
You can’t perform that action at this time.
0 commit comments