File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ type bits = u64;
1212/// `Tokens` doesn't include whitespace and comments. Main input to the parser.
1313///
1414/// Struct of arrays internally, but this shouldn't really matter.
15- #[ derive( Default ) ]
1615pub struct Input {
1716 kind : Vec < SyntaxKind > ,
1817 joint : Vec < bits > ,
@@ -21,6 +20,14 @@ pub struct Input {
2120
2221/// `pub` impl used by callers to create `Tokens`.
2322impl 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+ }
2431 #[ inline]
2532 pub fn push ( & mut self , kind : SyntaxKind ) {
2633 self . push_impl ( kind, SyntaxKind :: EOF )
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ pub enum StrStep<'a> {
2727impl LexedStr < ' _ > {
2828 pub fn to_input ( & self , edition : Edition ) -> crate :: Input {
2929 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 ( ) ) ;
3131 let mut was_joint = false ;
3232 for i in 0 ..self . len ( ) {
3333 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>(
1212 buffer : tt:: TokenTreesView < ' _ , SpanData < Ctx > > ,
1313 span_to_edition : & mut dyn FnMut ( Ctx ) -> Edition ,
1414) -> parser:: Input {
15- let mut res = parser:: Input :: default ( ) ;
15+ let mut res = parser:: Input :: with_capacity ( buffer . len ( ) ) ;
1616
1717 let mut current = buffer. cursor ( ) ;
1818 let mut syntax_context_to_edition_cache = FxHashMap :: default ( ) ;
You can’t perform that action at this time.
0 commit comments