Skip to content

Commit 5adff35

Browse files
committed
---
yaml --- r: 233719 b: refs/heads/beta c: fc7c0f9 h: refs/heads/master i: 233717: 4e1e5e4 233715: f6b1a4b 233711: a2be484 v: v3
1 parent cc9b7f3 commit 5adff35

File tree

6 files changed

+36
-127
lines changed

6 files changed

+36
-127
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: ef3255b063a28ef1ed8346192325cfac66398739
26+
refs/heads/beta: fc7c0f99d7cb5616230f7a61e86bcb4fc01dab5e
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 370fe2786109360f7c35b8ba552b83b773dd71d6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/doc/reference.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,15 +1881,11 @@ type int8_t = i8;
18811881
- `no_start` - disable linking to the `native` crate, which specifies the
18821882
"start" language item.
18831883
- `no_std` - disable linking to the `std` crate.
1884-
- `plugin` - load a list of named crates as compiler plugins, e.g.
1884+
- `plugin` load a list of named crates as compiler plugins, e.g.
18851885
`#![plugin(foo, bar)]`. Optional arguments for each plugin,
18861886
i.e. `#![plugin(foo(... args ...))]`, are provided to the plugin's
18871887
registrar function. The `plugin` feature gate is required to use
18881888
this attribute.
1889-
- `recursion_limit` - Sets the maximum depth for potentially
1890-
infinitely-recursive compile-time operations like
1891-
auto-dereference or macro expansion. The default is
1892-
`#![recursion_limit="64"]`.
18931889

18941890
### Module-only attributes
18951891

branches/beta/src/libcore/iter.rs

Lines changed: 25 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub trait Iterator {
184184
fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter> where
185185
Self: Sized, U: IntoIterator<Item=Self::Item>,
186186
{
187-
Chain{a: self, b: other.into_iter(), state: ChainState::Both}
187+
Chain{a: self, b: other.into_iter(), flag: false}
188188
}
189189

190190
/// Creates an iterator that iterates over both this and the specified
@@ -1277,30 +1277,7 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
12771277
pub struct Chain<A, B> {
12781278
a: A,
12791279
b: B,
1280-
state: ChainState,
1281-
}
1282-
1283-
// The iterator protocol specifies that iteration ends with the return value
1284-
// `None` from `.next()` (or `.next_back()`) and it is unspecified what
1285-
// further calls return. The chain adaptor must account for this since it uses
1286-
// two subiterators.
1287-
//
1288-
// It uses three states:
1289-
//
1290-
// - Both: `a` and `b` are remaining
1291-
// - Front: `a` remaining
1292-
// - Back: `b` remaining
1293-
//
1294-
// The fourth state (neither iterator is remaining) only occurs after Chain has
1295-
// returned None once, so we don't need to store this state.
1296-
#[derive(Clone)]
1297-
enum ChainState {
1298-
// both front and back iterator are remaining
1299-
Both,
1300-
// only front is remaining
1301-
Front,
1302-
// only back is remaining
1303-
Back,
1280+
flag: bool,
13041281
}
13051282

13061283
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1312,58 +1289,42 @@ impl<A, B> Iterator for Chain<A, B> where
13121289

13131290
#[inline]
13141291
fn next(&mut self) -> Option<A::Item> {
1315-
match self.state {
1316-
ChainState::Both => match self.a.next() {
1317-
elt @ Some(..) => return elt,
1318-
None => {
1319-
self.state = ChainState::Back;
1320-
self.b.next()
1321-
}
1322-
},
1323-
ChainState::Front => self.a.next(),
1324-
ChainState::Back => self.b.next(),
1292+
if self.flag {
1293+
self.b.next()
1294+
} else {
1295+
match self.a.next() {
1296+
Some(x) => return Some(x),
1297+
_ => ()
1298+
}
1299+
self.flag = true;
1300+
self.b.next()
13251301
}
13261302
}
13271303

13281304
#[inline]
13291305
fn count(self) -> usize {
1330-
match self.state {
1331-
ChainState::Both => self.a.count() + self.b.count(),
1332-
ChainState::Front => self.a.count(),
1333-
ChainState::Back => self.b.count(),
1334-
}
1306+
(if !self.flag { self.a.count() } else { 0 }) + self.b.count()
13351307
}
13361308

13371309
#[inline]
13381310
fn nth(&mut self, mut n: usize) -> Option<A::Item> {
1339-
match self.state {
1340-
ChainState::Both | ChainState::Front => {
1341-
for x in self.a.by_ref() {
1342-
if n == 0 {
1343-
return Some(x)
1344-
}
1345-
n -= 1;
1346-
}
1347-
if let ChainState::Both = self.state {
1348-
self.state = ChainState::Back;
1311+
if !self.flag {
1312+
for x in self.a.by_ref() {
1313+
if n == 0 {
1314+
return Some(x)
13491315
}
1316+
n -= 1;
13501317
}
1351-
ChainState::Back => {}
1352-
}
1353-
if let ChainState::Back = self.state {
1354-
self.b.nth(n)
1355-
} else {
1356-
None
1318+
self.flag = true;
13571319
}
1320+
self.b.nth(n)
13581321
}
13591322

13601323
#[inline]
13611324
fn last(self) -> Option<A::Item> {
1362-
match self.state {
1363-
ChainState::Both => self.b.last().or(self.a.last()),
1364-
ChainState::Front => self.a.last(),
1365-
ChainState::Back => self.b.last()
1366-
}
1325+
let a_last = if self.flag { None } else { self.a.last() };
1326+
let b_last = self.b.last();
1327+
b_last.or(a_last)
13671328
}
13681329

13691330
#[inline]
@@ -1389,16 +1350,9 @@ impl<A, B> DoubleEndedIterator for Chain<A, B> where
13891350
{
13901351
#[inline]
13911352
fn next_back(&mut self) -> Option<A::Item> {
1392-
match self.state {
1393-
ChainState::Both => match self.b.next_back() {
1394-
elt @ Some(..) => return elt,
1395-
None => {
1396-
self.state = ChainState::Front;
1397-
self.a.next_back()
1398-
}
1399-
},
1400-
ChainState::Front => self.a.next_back(),
1401-
ChainState::Back => self.b.next_back(),
1353+
match self.b.next_back() {
1354+
Some(x) => Some(x),
1355+
None => self.a.next_back()
14021356
}
14031357
}
14041358
}

branches/beta/src/libcoretest/iter.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -729,26 +729,6 @@ fn test_double_ended_chain() {
729729
assert_eq!(it.next_back().unwrap(), &5);
730730
assert_eq!(it.next_back().unwrap(), &7);
731731
assert_eq!(it.next_back(), None);
732-
733-
734-
// test that .chain() is well behaved with an unfused iterator
735-
struct CrazyIterator(bool);
736-
impl CrazyIterator { fn new() -> CrazyIterator { CrazyIterator(false) } }
737-
impl Iterator for CrazyIterator {
738-
type Item = i32;
739-
fn next(&mut self) -> Option<i32> {
740-
if self.0 { Some(99) } else { self.0 = true; None }
741-
}
742-
}
743-
744-
impl DoubleEndedIterator for CrazyIterator {
745-
fn next_back(&mut self) -> Option<i32> {
746-
self.next()
747-
}
748-
}
749-
750-
assert_eq!(CrazyIterator::new().chain(0..10).rev().last(), Some(0));
751-
assert!((0..10).chain(CrazyIterator::new()).rev().any(|i| i == 0));
752732
}
753733

754734
#[test]

branches/beta/src/libstd/collections/mod.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
//!
2626
//! Rust's collections can be grouped into four major categories:
2727
//!
28-
//! * Sequences: `Vec`, `VecDeque`, `LinkedList`, `BitVec`
29-
//! * Maps: `HashMap`, `BTreeMap`, `VecMap`
30-
//! * Sets: `HashSet`, `BTreeSet`, `BitSet`
28+
//! * Sequences: `Vec`, `VecDeque`, `LinkedList`
29+
//! * Maps: `HashMap`, `BTreeMap`
30+
//! * Sets: `HashSet`, `BTreeSet`
3131
//! * Misc: `BinaryHeap`
3232
//!
3333
//! # When Should You Use Which Collection?
@@ -70,22 +70,11 @@
7070
//! * You want to be able to get all of the entries in order on-demand.
7171
//! * You want a sorted map.
7272
//!
73-
//! ### Use a `VecMap` when:
74-
//! * You want a `HashMap` but with known to be small `usize` keys.
75-
//! * You want a `BTreeMap`, but with known to be small `usize` keys.
76-
//!
7773
//! ### Use the `Set` variant of any of these `Map`s when:
7874
//! * You just want to remember which keys you've seen.
7975
//! * There is no meaningful value to associate with your keys.
8076
//! * You just want a set.
8177
//!
82-
//! ### Use a `BitVec` when:
83-
//! * You want to store an unbounded number of booleans in a small space.
84-
//! * You want a bit vector.
85-
//!
86-
//! ### Use a `BitSet` when:
87-
//! * You want a `BitVec`, but want `Set` properties
88-
//!
8978
//! ### Use a `BinaryHeap` when:
9079
//!
9180
//! * You want to store a bunch of elements, but only ever want to process the
@@ -123,31 +112,20 @@
123112
//! | Vec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
124113
//! | VecDeque | O(1) | O(min(i, n-i))* | O(min(i, n-i)) | O(m)* | O(min(i, n-i)) |
125114
//! | LinkedList | O(min(i, n-i)) | O(min(i, n-i)) | O(min(i, n-i)) | O(1) | O(min(i, n-i)) |
126-
//! | BitVec | O(1) | O(n-i)* | O(n-i) | O(m)* | O(n-i) |
127115
//!
128116
//! Note that where ties occur, Vec is generally going to be faster than VecDeque, and VecDeque
129-
//! is generally going to be faster than LinkedList. BitVec is not a general purpose collection, and
130-
//! therefore cannot reasonably be compared.
117+
//! is generally going to be faster than LinkedList.
131118
//!
132119
//! ## Maps
133120
//!
134-
//! For Sets, all operations have the cost of the equivalent Map operation. For
135-
//! BitSet,
136-
//! refer to VecMap.
121+
//! For Sets, all operations have the cost of the equivalent Map operation.
137122
//!
138123
//! | | get | insert | remove | predecessor |
139124
//! |----------|-----------|----------|----------|-------------|
140125
//! | HashMap | O(1)~ | O(1)~* | O(1)~ | N/A |
141126
//! | BTreeMap | O(log n) | O(log n) | O(log n) | O(log n) |
142-
//! | VecMap | O(1) | O(1)? | O(1) | O(n) |
143-
//!
144-
//! Note that VecMap is *incredibly* inefficient in terms of space. The O(1)
145-
//! insertion time assumes space for the element is already allocated.
146-
//! Otherwise, a large key may require a massive reallocation, with no direct
147-
//! relation to the number of elements in the collection. VecMap should only be
148-
//! seriously considered for small keys.
149127
//!
150-
//! Note also that BTreeMap's precise performance depends on the value of B.
128+
//! Note that BTreeMap's precise performance depends on the value of B.
151129
//!
152130
//! # Correct and Efficient Usage of Collections
153131
//!

branches/beta/src/libstd/sys/windows/os.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ pub fn error_string(errnum: i32) -> String {
7474
langId,
7575
buf.as_mut_ptr(),
7676
buf.len() as DWORD,
77-
ptr::null()) as usize;
77+
ptr::null());
7878
if res == 0 {
7979
// Sometimes FormatMessageW can fail e.g. system doesn't like langId,
8080
let fm_err = errno();
8181
return format!("OS Error {} (FormatMessageW() returned error {})",
8282
errnum, fm_err);
8383
}
8484

85-
match String::from_utf16(&buf[..res]) {
85+
let b = buf.iter().position(|&b| b == 0).unwrap_or(buf.len());
86+
match String::from_utf16(&buf[..b]) {
8687
Ok(mut msg) => {
8788
// Trim trailing CRLF inserted by FormatMessageW
8889
let len = msg.trim_right().len();

0 commit comments

Comments
 (0)