Skip to content

Commit

Permalink
Avoid excessive reallocations during item-bodies checking
Browse files Browse the repository at this point in the history
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%
```
  • Loading branch information
dotdash committed Feb 26, 2016
1 parent f59fd46 commit 31fef23
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 31fef23

Please sign in to comment.