about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2016-02-27 08:04:54 +0530
committerManish Goregaokar <manishsmail@gmail.com>2016-02-27 10:52:02 +0530
commit543c6a37c012e1bc4f2c64df541a2782a91021ac (patch)
tree52af2fe6a635222bfae87d1936fa1f6a5bc449eb
parent2d1843ad9dd398102c6550be2688ae955b19499c (diff)
parent31fef237b639fac3a1b719110fa0cfad3df44332 (diff)
downloadrust-543c6a37c012e1bc4f2c64df541a2782a91021ac.tar.gz
rust-543c6a37c012e1bc4f2c64df541a2782a91021ac.zip
Rollup merge of #31929 - dotdash:less_rallocx, r=alexcrichton
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.rs5
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> {