aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/smallvec.rs
diff options
context:
space:
mode:
authorClark Gaebel <cgaebel@mozilla.com>2014-10-28 10:36:41 -0700
committerClark Gaebel <cgaebel@mozilla.com>2014-10-28 10:36:41 -0700
commitfe363996282a069bb38a3449da59bc411fa9d066 (patch)
tree5433a13625dc563e0894eda3dda070bdfabbaeb9 /components/util/smallvec.rs
parent4d610e36bdbd1213a9cb1d25fb796792040a0d25 (diff)
downloadservo-fe363996282a069bb38a3449da59bc411fa9d066.tar.gz
servo-fe363996282a069bb38a3449da59bc411fa9d066.zip
use size hints
Diffstat (limited to 'components/util/smallvec.rs')
-rw-r--r--components/util/smallvec.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/components/util/smallvec.rs b/components/util/smallvec.rs
index 00c43b76b9e..139c1d09300 100644
--- a/components/util/smallvec.rs
+++ b/components/util/smallvec.rs
@@ -405,6 +405,12 @@ macro_rules! def_small_vector(
fn from_iter<I: Iterator<T>>(mut iter: I) -> $name<T> {
let mut v = $name::new();
+ let (lower_size_bound, _) = iter.size_hint();
+
+ if lower_size_bound > v.cap() {
+ v.grow(lower_size_bound);
+ }
+
for elem in iter {
v.push(elem);
}
@@ -415,6 +421,14 @@ macro_rules! def_small_vector(
impl<T: 'static> Extendable<T> for $name<T> {
fn extend<I: Iterator<T>>(&mut self, mut iter: I) {
+ let (lower_size_bound, _) = iter.size_hint();
+
+ let target_len = self.len() + lower_size_bound;
+
+ if target_len > self.cap() {
+ v.grow(target_len);
+ }
+
for elem in iter {
self.push(elem);
}