]> git.lizzy.rs Git - rust.git/commitdiff
Avoid excessive reallocations during item-bodies checking
authorBjörn Steinbrink <bsteinbr@gmail.com>
Fri, 26 Feb 2016 23:53:33 +0000 (00:53 +0100)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Fri, 26 Feb 2016 23:59:43 +0000 (00:59 +0100)
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%
```

src/librustc/middle/subst.rs

index ddc817ffc023e0ee5c40c8436367334f6ff9cba9..f8c6d3d934123bb0b38f2ac9e18a1fc6fc56be14 100644 (file)
@@ -555,6 +555,11 @@ fn next(&mut self) -> Option<(ParamSpace, usize, &'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> {