Skip to content

Commit dfb7de8

Browse files
committed
auto merge of #7334 : thestinger/rust/old_iter, r=Aatch
the `test/run-pass/class-trait-bounded-param.rs` test was xfailed and written in an ancient dialect of Rust so I've just removed it this also removes `to_vec` from DList because it's provided by `std::iter::to_vec` an Iterator implementation is added for OptVec but some transitional internal iterator methods are still left
2 parents 832fe32 + da1a9a3 commit dfb7de8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+257
-799
lines changed

src/libextra/bitv.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,8 @@ impl BitvSet {
666666
pub fn symmetric_difference_with(&mut self, other: &BitvSet) {
667667
self.other_op(other, |w1, w2| w1 ^ w2);
668668
}
669-
}
670-
671-
impl BaseIter<uint> for BitvSet {
672-
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
673669

674-
fn each(&self, blk: &fn(v: &uint) -> bool) -> bool {
670+
pub fn each(&self, blk: &fn(v: &uint) -> bool) -> bool {
675671
for self.bitv.storage.iter().enumerate().advance |(i, &w)| {
676672
if !iterate_bits(i * uint::bits, w, |b| blk(&b)) {
677673
return false;

src/libextra/dlist.rs

+36-58
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ Do not use ==, !=, <, etc on doubly-linked lists -- it may not terminate.
2121
use core::prelude::*;
2222

2323
use core::managed;
24-
use core::old_iter;
25-
use core::vec;
2624

2725
pub type DListLink<T> = Option<@mut DListNode<T>>;
2826

@@ -213,6 +211,42 @@ impl<T> DList<T> {
213211
}
214212

215213
impl<T> DList<T> {
214+
/**
215+
* Iterates through the current contents.
216+
*
217+
* Attempts to access this dlist during iteration are allowed (to
218+
* allow for e.g. breadth-first search with in-place enqueues), but
219+
* removing the current node is forbidden.
220+
*/
221+
pub fn each(@mut self, f: &fn(v: &T) -> bool) -> bool {
222+
let mut link = self.peek_n();
223+
while link.is_some() {
224+
let nobe = link.get();
225+
assert!(nobe.linked);
226+
227+
{
228+
let frozen_nobe = &*nobe;
229+
if !f(&frozen_nobe.data) { return false; }
230+
}
231+
232+
// Check (weakly) that the user didn't do a remove.
233+
if self.size == 0 {
234+
fail!("The dlist became empty during iteration??")
235+
}
236+
if !nobe.linked ||
237+
(!((nobe.prev.is_some()
238+
|| managed::mut_ptr_eq(self.hd.expect("headless dlist?"),
239+
nobe))
240+
&& (nobe.next.is_some()
241+
|| managed::mut_ptr_eq(self.tl.expect("tailless dlist?"),
242+
nobe)))) {
243+
fail!("Removing a dlist node during iteration is forbidden!")
244+
}
245+
link = nobe.next_link();
246+
}
247+
return true;
248+
}
249+
216250
/// Get the size of the list. O(1).
217251
pub fn len(@mut self) -> uint { self.size }
218252
/// Returns true if the list is empty. O(1).
@@ -484,56 +518,6 @@ impl<T:Copy> DList<T> {
484518

485519
/// Get data at the list's tail, failing if empty. O(1).
486520
pub fn tail(@mut self) -> T { copy self.tail_n().data }
487-
488-
/// Get the elements of the list as a vector. O(n).
489-
pub fn to_vec(@mut self) -> ~[T] {
490-
let mut v = vec::with_capacity(self.size);
491-
for old_iter::eachi(&self) |index,data| {
492-
v[index] = copy *data;
493-
}
494-
v
495-
}
496-
}
497-
498-
impl<T> BaseIter<T> for @mut DList<T> {
499-
/**
500-
* Iterates through the current contents.
501-
*
502-
* Attempts to access this dlist during iteration are allowed (to
503-
* allow for e.g. breadth-first search with in-place enqueues), but
504-
* removing the current node is forbidden.
505-
*/
506-
fn each(&self, f: &fn(v: &T) -> bool) -> bool {
507-
let mut link = self.peek_n();
508-
while link.is_some() {
509-
let nobe = link.get();
510-
assert!(nobe.linked);
511-
512-
{
513-
let frozen_nobe = &*nobe;
514-
if !f(&frozen_nobe.data) { return false; }
515-
}
516-
517-
// Check (weakly) that the user didn't do a remove.
518-
if self.size == 0 {
519-
fail!("The dlist became empty during iteration??")
520-
}
521-
if !nobe.linked ||
522-
(!((nobe.prev.is_some()
523-
|| managed::mut_ptr_eq(self.hd.expect("headless dlist?"),
524-
nobe))
525-
&& (nobe.next.is_some()
526-
|| managed::mut_ptr_eq(self.tl.expect("tailless dlist?"),
527-
nobe)))) {
528-
fail!("Removing a dlist node during iteration is forbidden!")
529-
}
530-
link = nobe.next_link();
531-
}
532-
return true;
533-
}
534-
535-
#[inline]
536-
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
537521
}
538522

539523
#[cfg(test)]
@@ -542,7 +526,6 @@ mod tests {
542526

543527
use super::*;
544528

545-
use core::old_iter;
546529
use core::vec;
547530

548531
#[test]
@@ -759,11 +742,6 @@ mod tests {
759742
assert_eq!(l.len(), 3);
760743
}
761744
#[test]
762-
fn test_dlist_foldl() {
763-
let l = from_vec(vec::from_fn(101, |x|x));
764-
assert_eq!(old_iter::foldl(&l, 0, |accum,elem| *accum+*elem), 5050);
765-
}
766-
#[test]
767745
fn test_dlist_break_early() {
768746
let l = from_vec([1,2,3,4,5]);
769747
let mut x = 0;

src/libextra/priority_queue.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,15 @@
1414

1515
use core::prelude::*;
1616

17-
use core::old_iter::BaseIter;
1817
use core::unstable::intrinsics::{move_val_init, init};
1918
use core::util::{replace, swap};
2019
use core::vec;
2120

22-
#[allow(missing_doc)]
21+
/// A priority queue implemented with a binary heap
2322
pub struct PriorityQueue<T> {
2423
priv data: ~[T],
2524
}
2625

27-
impl<T:Ord> BaseIter<T> for PriorityQueue<T> {
28-
/// Visit all values in the underlying vector.
29-
///
30-
/// The values are **not** visited in order.
31-
fn each(&self, f: &fn(&T) -> bool) -> bool { self.data.iter().advance(f) }
32-
33-
fn size_hint(&self) -> Option<uint> { Some(self.data.len()) }
34-
}
35-
3626
impl<T:Ord> Container for PriorityQueue<T> {
3727
/// Returns the length of the queue
3828
fn len(&self) -> uint { self.data.len() }
@@ -47,6 +37,11 @@ impl<T:Ord> Mutable for PriorityQueue<T> {
4737
}
4838

4939
impl<T:Ord> PriorityQueue<T> {
40+
/// Visit all values in the underlying vector.
41+
///
42+
/// The values are **not** visited in order.
43+
pub fn each(&self, f: &fn(&T) -> bool) -> bool { self.data.iter().advance(f) }
44+
5045
/// Returns the greatest item in the queue - fails if empty
5146
pub fn top<'a>(&'a self) -> &'a T { &self.data[0] }
5247

src/libextra/smallintmap.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use core::prelude::*;
1919

2020
use core::cmp;
2121
use core::container::{Container, Mutable, Map, Set};
22-
use core::old_iter::BaseIter;
23-
use core::old_iter;
2422
use core::uint;
2523
use core::util::replace;
2624
use core::vec;
@@ -212,12 +210,6 @@ impl Mutable for SmallIntSet {
212210
fn clear(&mut self) { self.map.clear() }
213211
}
214212

215-
impl BaseIter<uint> for SmallIntSet {
216-
/// Visit all values in order
217-
fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
218-
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
219-
}
220-
221213
impl Set<uint> for SmallIntSet {
222214
/// Return true if the set contains a value
223215
fn contains(&self, value: &uint) -> bool { self.map.contains_key(value) }
@@ -233,12 +225,14 @@ impl Set<uint> for SmallIntSet {
233225
/// Return true if the set has no elements in common with `other`.
234226
/// This is equivalent to checking for an empty uintersection.
235227
fn is_disjoint(&self, other: &SmallIntSet) -> bool {
236-
old_iter::all(self, |v| !other.contains(v))
228+
for self.each |v| { if other.contains(v) { return false } }
229+
true
237230
}
238231

239232
/// Return true if the set is a subset of another
240233
fn is_subset(&self, other: &SmallIntSet) -> bool {
241-
old_iter::all(self, |v| other.contains(v))
234+
for self.each |v| { if !other.contains(v) { return false } }
235+
true
242236
}
243237

244238
/// Return true if the set is a superset of another
@@ -286,6 +280,9 @@ impl Set<uint> for SmallIntSet {
286280
impl SmallIntSet {
287281
/// Create an empty SmallIntSet
288282
pub fn new() -> SmallIntSet { SmallIntSet{map: SmallIntMap::new()} }
283+
284+
/// Visit all values in order
285+
pub fn each(&self, f: &fn(&uint) -> bool) -> bool { self.map.each_key(f) }
289286
}
290287

291288
#[cfg(test)]

src/libextra/treemap.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -249,22 +249,6 @@ pub struct TreeSet<T> {
249249
priv map: TreeMap<T, ()>
250250
}
251251

252-
impl<T: TotalOrd> BaseIter<T> for TreeSet<T> {
253-
/// Visit all values in order
254-
#[inline]
255-
fn each(&self, f: &fn(&T) -> bool) -> bool { self.map.each_key(f) }
256-
#[inline]
257-
fn size_hint(&self) -> Option<uint> { Some(self.len()) }
258-
}
259-
260-
impl<T: TotalOrd> ReverseIter<T> for TreeSet<T> {
261-
/// Visit all values in reverse order
262-
#[inline]
263-
fn each_reverse(&self, f: &fn(&T) -> bool) -> bool {
264-
self.map.each_key_reverse(f)
265-
}
266-
}
267-
268252
impl<T: Eq + TotalOrd> Eq for TreeSet<T> {
269253
#[inline]
270254
fn eq(&self, other: &TreeSet<T>) -> bool { self.map == other.map }
@@ -499,6 +483,16 @@ impl<T: TotalOrd> TreeSet<T> {
499483
pub fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> {
500484
TreeSetIterator{iter: self.map.iter()}
501485
}
486+
487+
/// Visit all values in order
488+
#[inline]
489+
pub fn each(&self, f: &fn(&T) -> bool) -> bool { self.map.each_key(f) }
490+
491+
/// Visit all values in reverse order
492+
#[inline]
493+
pub fn each_reverse(&self, f: &fn(&T) -> bool) -> bool {
494+
self.map.each_key_reverse(f)
495+
}
502496
}
503497

504498
/// Lazy forward iterator over a set

src/librustc/metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
731731
}
732732

733733
let mut combined_ty_params = opt_vec::Empty;
734-
combined_ty_params.push_all(&owner_generics.ty_params);
735-
combined_ty_params.push_all(&method_generics.ty_params);
734+
for owner_generics.ty_params.each |x| { combined_ty_params.push(copy *x) }
735+
for method_generics.ty_params.each |x| { combined_ty_params.push(copy *x) }
736736
let len = combined_ty_params.len();
737737
encode_type_param_bounds(ebml_w, ecx, &combined_ty_params);
738738

src/librustc/middle/borrowck/move_data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl FlowedMoveData {
507507
for self.dfcx_moves.each_bit_on_entry_frozen(id) |index| {
508508
let move = &self.move_data.moves[index];
509509
let moved_path = move.path;
510-
if base_indices.contains(&moved_path) {
510+
if base_indices.iter().any_(|x| x == &moved_path) {
511511
// Scenario 1 or 2: `loan_path` or some base path of
512512
// `loan_path` was moved.
513513
if !f(move, self.move_data.path(moved_path).loan_path) {
@@ -536,7 +536,7 @@ impl FlowedMoveData {
536536
-> bool {
537537
//! True if `id` is the id of the LHS of an assignment
538538
539-
self.move_data.assignee_ids.contains(&id)
539+
self.move_data.assignee_ids.iter().any_(|x| x == &id)
540540
}
541541

542542
pub fn each_assignment_of(&self,

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3710,7 +3710,7 @@ impl Resolver {
37103710
let function_type_rib = @Rib(rib_kind);
37113711
self.type_ribs.push(function_type_rib);
37123712

3713-
for generics.ty_params.eachi |index, type_parameter| {
3713+
for generics.ty_params.iter().enumerate().advance |(index, type_parameter)| {
37143714
let name = type_parameter.ident;
37153715
debug!("with_type_parameter_rib: %d %d", node_id,
37163716
type_parameter.id);

src/libstd/at_vec.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use cast::transmute;
1414
use container::Container;
1515
use iterator::IteratorUtil;
1616
use kinds::Copy;
17-
use old_iter;
1817
use option::Option;
1918
use sys;
2019
use uint;
@@ -129,7 +128,7 @@ pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
129128
* Creates an immutable vector of size `n_elts` and initializes the elements
130129
* to the value returned by the function `op`.
131130
*/
132-
pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> @[T] {
131+
pub fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> @[T] {
133132
do build_sized(n_elts) |push| {
134133
let mut i: uint = 0u;
135134
while i < n_elts { push(op(i)); i += 1u; }

src/libstd/clone.rs

+12
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ impl<'self, T> Clone for &'self T {
5656
fn clone(&self) -> &'self T { *self }
5757
}
5858

59+
impl<'self, T> Clone for &'self [T] {
60+
/// Return a shallow copy of the slice.
61+
#[inline]
62+
fn clone(&self) -> &'self [T] { *self }
63+
}
64+
65+
impl<'self> Clone for &'self str {
66+
/// Return a shallow copy of the slice.
67+
#[inline]
68+
fn clone(&self) -> &'self str { *self }
69+
}
70+
5971
macro_rules! clone_impl(
6072
($t:ty) => {
6173
impl Clone for $t {

src/libstd/core.rc

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ pub mod from_str;
138138
#[path = "num/num.rs"]
139139
pub mod num;
140140
pub mod iter;
141-
pub mod old_iter;
142141
pub mod iterator;
143142
pub mod to_str;
144143
pub mod to_bytes;

src/libstd/iterator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ implementing the `Iterator` trait.
2020
#[allow(default_methods)]; // solid enough for the use case here
2121

2222
use cmp;
23-
use iter::{FromIter, Times};
23+
use iter::Times;
2424
use num::{Zero, One};
2525
use option::{Option, Some, None};
2626
use ops::{Add, Mul};
@@ -240,7 +240,7 @@ pub trait IteratorUtil<A> {
240240
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
241241

242242
/// Loops through the entire iterator, collecting all of the elements into
243-
/// a container implementing `FromIter`.
243+
/// a container implementing `FromIterator`.
244244
///
245245
/// # Example
246246
///
@@ -249,7 +249,7 @@ pub trait IteratorUtil<A> {
249249
/// let b: ~[int] = a.iter().transform(|&x| x).collect();
250250
/// assert!(a == b);
251251
/// ~~~
252-
fn collect<B: FromIter<A>>(&mut self) -> B;
252+
fn collect<B: FromIterator<A, Self>>(&mut self) -> B;
253253

254254
/// Loops through `n` iterations, returning the `n`th element of the
255255
/// iterator.
@@ -411,8 +411,8 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
411411
}
412412

413413
#[inline]
414-
fn collect<B: FromIter<A>>(&mut self) -> B {
415-
FromIter::from_iter::<A, B>(|f| self.advance(f))
414+
fn collect<B: FromIterator<A, T>>(&mut self) -> B {
415+
FromIterator::from_iterator(self)
416416
}
417417

418418
/// Return the `n`th item yielded by an iterator.

0 commit comments

Comments
 (0)