diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2018-08-12 23:26:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-12 23:26:49 +0200 |
| commit | 7d3864954ef5bc2a076aa9db9da12b0481425a07 (patch) | |
| tree | 5e77b8aaf403d926300562e20ceb256d354f0369 /src/libsyntax | |
| parent | 0653c259c23c1b71738dcc96e3a4d8105f74b258 (diff) | |
| parent | b68b3965a241e47c232613f403fbace64fd8b876 (diff) | |
| download | rust-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.rs | 6 |
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, |
