diff options
| author | Björn Steinbrink <bsteinbr@gmail.com> | 2016-02-27 00:53:33 +0100 |
|---|---|---|
| committer | Björn Steinbrink <bsteinbr@gmail.com> | 2016-02-27 00:59:43 +0100 |
| commit | 31fef237b639fac3a1b719110fa0cfad3df44332 (patch) | |
| tree | f4ad64cba631febeb8b57c303fd0bafec953debd | |
| parent | f59fd4642534e80a61982ce3e10c147d97054212 (diff) | |
| download | rust-31fef237b639fac3a1b719110fa0cfad3df44332.tar.gz rust-31fef237b639fac3a1b719110fa0cfad3df44332.zip | |
Avoid excessive reallocations during item-bodies checking
When foldings Substs, we map over VecPerParamSpace instances using EnumeratedItems which does not provide an accurate size_hint() in its Iterator implementation. This leads to quite a large number or reallocations. Providing a suitable size_hint() implementation reduces the time spent in item-bodies checking quite a bit. ``` crate | before | after | ~change -------|------------------------- core | 7.28s | 5.44s | -25% std | 2.07s | 1.88s | -9.2% syntax | 8.86s | 8.30s | -6.3% ```
| -rw-r--r-- | src/librustc/middle/subst.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index ddc817ffc02..f8c6d3d9341 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -555,6 +555,11 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> { None } } + + fn size_hint(&self) -> (usize, Option<usize>) { + let size = self.vec.as_slice().len(); + (size, Some(size)) + } } impl<T> IntoIterator for VecPerParamSpace<T> { |
