about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-08-12 23:26:49 +0200
committerGitHub <noreply@github.com>2018-08-12 23:26:49 +0200
commit7d3864954ef5bc2a076aa9db9da12b0481425a07 (patch)
tree5e77b8aaf403d926300562e20ceb256d354f0369 /src/libsyntax
parent0653c259c23c1b71738dcc96e3a4d8105f74b258 (diff)
parentb68b3965a241e47c232613f403fbace64fd8b876 (diff)
downloadrust-7d3864954ef5bc2a076aa9db9da12b0481425a07.tar.gz
rust-7d3864954ef5bc2a076aa9db9da12b0481425a07.zip
Rollup merge of #53019 - ljedrz:bad_collects, r=estebank
Don't collect() when size_hint is useless

This adjusts PRs #52738 and #52697 by falling back to calculating capacity and extending or pushing in a loop where `collect()` can't be trusted to calculate the right capacity.

It is a performance win.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 28c1e4324de..6925ed2afb8 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -501,7 +501,11 @@ impl Pat {
             PatKind::Slice(pats, None, _) if pats.len() == 1 =>
                 pats[0].to_ty().map(TyKind::Slice)?,
             PatKind::Tuple(pats, None) => {
-                let tys = pats.iter().map(|pat| pat.to_ty()).collect::<Option<Vec<_>>>()?;
+                let mut tys = Vec::with_capacity(pats.len());
+                // FIXME(#48994) - could just be collected into an Option<Vec>
+                for pat in pats {
+                    tys.push(pat.to_ty()?);
+                }
                 TyKind::Tup(tys)
             }
             _ => return None,