Skip to content

Commit

Permalink
Preallocate TokenBuffer vector
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 25, 2022
1 parent 93f03d3 commit fc1a189
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ impl TokenBuffer {
fn inner_new(stream: TokenStream, up: *const Entry) -> TokenBuffer {
// Build up the entries list, recording the locations of any Groups
// in the list to be processed later.
let mut entries = Vec::new();
let iterator = stream.into_iter();
let mut entries = Vec::with_capacity(iterator.size_hint().0 + 1);
let mut groups = Vec::new();
for tt in stream {
for tt in iterator {
match tt {
TokenTree::Ident(ident) => {
entries.push(Entry::Ident(ident));
Expand Down

0 comments on commit fc1a189

Please sign in to comment.