Skip to content

Commit 14ca526

Browse files
committed
---
yaml --- r: 64781 b: refs/heads/snap-stage3 c: fe955e7 h: refs/heads/master i: 64779: 300edec v: v3
1 parent 41b2ccb commit 14ca526

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: ffe549daf5b718226490b9e0b677d9876c807f4e
4+
refs/heads/snap-stage3: fe955e7b062f8787f9df7e9c36abc1b83485fead
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/iterator.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ pub trait FromIterator<A, T: Iterator<A>> {
3232
fn from_iterator(iterator: &mut T) -> Self;
3333
}
3434

35+
/// A type growable from an `Iterator` implementation
36+
pub trait Extendable<A, T: Iterator<A>>: FromIterator<A, T> {
37+
/// Extend a container with the elements yielded by an iterator
38+
fn extend(&mut self, iterator: &mut T);
39+
}
40+
3541
/// An interface for dealing with "external iterators". These types of iterators
3642
/// can be resumed at any time as all state is stored internally as opposed to
3743
/// being located on the call stack.

branches/snap-stage3/src/libstd/vec.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,7 @@ impl<T> Iterator<T> for VecConsumeRevIterator<T> {
22242224
}
22252225

22262226
impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
2227-
pub fn from_iterator(iterator: &mut T) -> ~[A] {
2227+
fn from_iterator(iterator: &mut T) -> ~[A] {
22282228
let (lower, _) = iterator.size_hint();
22292229
let mut xs = with_capacity(lower);
22302230
for iterator.advance |x| {
@@ -2234,6 +2234,17 @@ impl<A, T: Iterator<A>> FromIterator<A, T> for ~[A] {
22342234
}
22352235
}
22362236

2237+
impl<A, T: Iterator<A>> Extendable<A, T> for ~[A] {
2238+
fn extend(&mut self, iterator: &mut T) {
2239+
let (lower, _) = iterator.size_hint();
2240+
let len = self.len();
2241+
self.reserve(len + lower);
2242+
for iterator.advance |x| {
2243+
self.push(x);
2244+
}
2245+
}
2246+
}
2247+
22372248
#[cfg(test)]
22382249
mod tests {
22392250
use option::{None, Option, Some};

0 commit comments

Comments
 (0)