Skip to content

Commit

Permalink
use size hints
Browse files Browse the repository at this point in the history
  • Loading branch information
Clark Gaebel committed Oct 28, 2014
1 parent 4d610e3 commit fe36399
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions components/util/smallvec.rs
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit fe36399

Please sign in to comment.