From fc1a189d119f711dbd15f685e9c56ba91e285b26 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 24 Jul 2022 21:47:35 -0700 Subject: [PATCH] Preallocate TokenBuffer vector --- src/buffer.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index cf280fa31d..26ff67c8d0 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -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));