Skip to content

Commit

Permalink
Merge pull request #1204 from dtolnay/prealloc
Browse files Browse the repository at this point in the history
Preallocate TokenBuffer vector
  • Loading branch information
dtolnay authored Jul 25, 2022
2 parents 93f03d3 + fc1a189 commit 5483326
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 5483326

Please sign in to comment.