summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2016-11-07Auto merge of #36365 - matthew-piziak:silent-overflow, r=eddybbors-6/+6
fix silent overflows on `Step` impls Part of https://github.com/rust-lang/rust/issues/36110 r? @eddyb
2016-11-05Auto merge of #37597 - alexcrichton:rollup, r=alexcrichtonbors-4/+1
Rollup of 24 pull requests - Successful merges: #37255, #37317, #37408, #37410, #37422, #37427, #37470, #37501, #37537, #37556, #37557, #37564, #37565, #37566, #37569, #37574, #37577, #37579, #37583, #37585, #37586, #37587, #37589, #37596 - Failed merges: #37521, #37547
2016-11-05Rollup merge of #37565 - mglagla:peek_use_as_ref, r=alexcrichtonAlex Crichton-4/+1
Peekable::peek(): Use Option::as_ref() Replace the match expression in .peek() with Option::as_ref() since it's the same functionality.
2016-11-04Auto merge of #37356 - cristicbz:wrapsum, r=alexcrichtonbors-6/+11
Add impls for `&Wrapping`. Also `Sum`, `Product` impls for both `Wrapping` and `&Wrapping`. There are two changes here (split into two commits): - Ops for references to `&Wrapping` (`Add`, `Sub`, `Mul` etc.) similar to the way they are implemented for primitives. - Impls for `iter::{Sum,Product}` for `Wrapping`. As far as I know `impl` stability attributes don't really matter so I didn't bother breaking up the macro for two different kinds of stability. Happy to change if it does matter.
2016-11-04Auto merge of #37306 - bluss:trusted-len, r=alexcrichtonbors-1/+76
Add Iterator trait TrustedLen to enable better FromIterator / Extend This trait attempts to improve FromIterator / Extend code by enabling it to trust the iterator to produce an exact number of elements, which means that reallocation needs to happen only once and is moved out of the loop. `TrustedLen` differs from `ExactSizeIterator` in that it attempts to include _more_ iterators by allowing for the case that the iterator's len does not fit in `usize`. Consumers must check for this case (for example they could panic, since they can't allocate a collection of that size). For example, chain can be TrustedLen and all numerical ranges can be TrustedLen. All they need to do is to report an exact size if it fits in `usize`, and `None` as the upper bound otherwise. The trait describes its contract like this: ``` An iterator that reports an accurate length using size_hint. The iterator reports a size hint where it is either exact (lower bound is equal to upper bound), or the upper bound is `None`. The upper bound must only be `None` if the actual iterator length is larger than `usize::MAX`. The iterator must produce exactly the number of elements it reported. This trait must only be implemented when the contract is upheld. Consumers of this trait must inspect `.size_hint()`’s upper bound. ``` Fixes #37232
2016-11-04Link the tracking issue for TrustedLenUlrik Sverdrup-10/+10
2016-11-03Peekable::peek(): Use Option::as_ref()Martin Glagla-4/+1
2016-10-26Auto merge of #37315 - bluss:fold-more, r=alexcrichtonbors-0/+32
Implement Iterator::fold for .chain(), .cloned(), .map() and the VecDeque iterators. Chain can do something interesting here where it passes on the fold into its inner iterators. The lets the underlying iterator's custom fold() be used, and skips the regular chain logic in next. Also implement .fold() specifically for .map() and .cloned() so that any inner fold improvements are available through map and cloned. The same way, a VecDeque iterator fold can be turned into two slice folds. These changes lend the power of the slice iterator's loop codegen to VecDeque, and to chains of slice iterators, and so on. It's an improvement for .sum() and .product(), and other uses of fold.
2016-10-25iter: Implement .fold() for .chain()Ulrik Sverdrup-0/+19
Chain can do something interesting here where it passes on the fold into its inner iterators. The lets the underlying iterator's custom fold() be used, and skips the regular chain logic in next.
2016-10-25iter: Implement .fold() for .cloned() and .map()Ulrik Sverdrup-0/+13
Implement .fold() specifically for .map() and .cloned() so that any inner fold improvements are available through map and cloned.
2016-10-23Add `Sum` and `Product` impls for `Wrapping`Cristi Cobzarenco-6/+11
2016-10-21doc: a more simple description of Iterator::nthTshepang Lekhonkhobe-6/+2
2016-10-20Document TrustedLen’s contractUlrik Sverdrup-1/+13
2016-10-20Implement TrustedLen for more iteratorsUlrik Sverdrup-3/+23
2016-10-20Introduce iterator trait TrustedLenUlrik Sverdrup-1/+44
2016-10-17Expand .zip() specialization to .map() and .cloned()Ulrik Sverdrup-0/+59
Implement .zip() specialization for Map and Cloned. The crucial thing for transparent specialization is that we want to preserve the potential side effects. The simplest example is that in this code snippet: `(0..6).map(f).zip((0..4).map(g)).count()` `f` will be called five times, and `g` four times. The last time for `f` is when the other iterator is at its end, so this element is unused. This side effect can be preserved without disturbing code generation for simple uses of `.map()`. The `Zip::next_back()` case is even more complicated, unfortunately.
2016-10-11remove erroneous semicolonsMatthew Piziak-6/+6
2016-10-09use UFCS with Add::add and Sub::sub instead of unstable attributesMatthew Piziak-12/+6
2016-10-01std: Correct stability attributes for some implementationsOliver Middleton-5/+7
These are displayed by rustdoc so should be correct.
2016-09-28Auto merge of #36395 - durka:rangeinclusive-no-esi, r=alexcrichtonbors-2/+9
remove ExactSizeIterator from RangeInclusive<{u,i}{32,size}> Fixes #36386. This is a [breaking-change] for nightly users of `#![feature(inclusive_range_syntax)]` and/or `#![feature(inclusive_range)]`.
2016-09-17Auto merge of #36490 - bluss:zip-slightly-despecialized-edition, r=alexcrichtonbors-38/+14
Remove data structure specialization for .zip() iterator Go back on half the specialization, the part that changed the Zip struct's fields themselves depending on the types of the iterators. Previous PR: #33090 This means that the Zip iterator will always carry two usize fields, which are sometimes unused. If a whole for loop using a .zip() iterator is inlined, these are simply removed and have no effect. The same improvement for Zip of for example slice iterators remain, and they still optimize well. However, like when the specialization of zip was merged, the compiler is still very sensistive to the exact context. For example this code only autovectorizes if the function is used, not if the code in zip_sum_i32 is inserted inline where it was called: ```rust fn zip_sum_i32(xs: &[i32], ys: &[i32]) -> i32 { let mut s = 0; for (&x, &y) in xs.iter().zip(ys) { s += x * y; } s } fn zipdot_i32_default_zip(b: &mut test::Bencher) { let xs = vec![1; 1024]; let ys = vec![1; 1024]; b.iter(|| { zip_sum_i32(&xs, &ys) }) } ``` Include a test that checks that `Zip<T, U>` is covariant w.r.t. T and U. Fixes #35727
2016-09-15Remove data structure specialization for .zip() iteratorUlrik Sverdrup-38/+14
Go back on half the specialization, the part that changed the Zip struct's fields themselves depending on the types of the iterators. This means that the Zip iterator will always carry two usize fields, which are unused. If a whole for loop using a .zip() iterator is inlined, these are simply removed and have no effect. The same improvement for Zip of for example slice iterators remain, and they still optimize well. However, like when the specialization of zip was merged, the compiler is still very sensistive to the exact context. For example this code only autovectorizes if the function is used, not if the code in zip_sum_i32 is inserted inline it was called: ``` fn zip_sum_i32(xs: &[i32], ys: &[i32]) -> i32 { let mut s = 0; for (&x, &y) in xs.iter().zip(ys) { s += x * y; } s } fn zipdot_i32_default_zip(b: &mut test::Bencher) { let xs = vec![1; 1024]; let ys = vec![1; 1024]; b.iter(|| { zip_sum_i32(&xs, &ys) }) } ``` Include a test that checks that Zip<T, U> is covariant w.r.t. T and U.
2016-09-12Remove stray attributeSteven Fackler-1/+0
2016-09-12remove ExactSizeIterator from RangeInclusive<u/isize>Alex Burka-2/+9
2016-09-10Inherit overflow checks for sum and productSteven Fackler-14/+11
2016-09-09fix silent overflows on `Step` implsMatthew Piziak-0/+6
r? @eddyb
2016-09-02Auto merge of #35856 - phimuemue:master, r=brsonbors-0/+53
Introduce max_by/min_by on iterators See https://github.com/rust-lang/rfcs/issues/1722 for reference. It seems that there is `min`, `max` (simple computation of min/max), `min_by_key`, `max_by_key` (min/max by comparing mapped values) but no `min_by` and `max_by` (min/max according to comparison function). However, e.g. on vectors or slices there is `sort`, `sort_by_key` and `sort_by`.
2016-08-29Changed issue number to 36105philipp-2/+2
2016-08-26accumulate vector and assert for RangeFrom and RangeInclusive examplesMatthew Piziak-22/+10
PR #35695 for `Range` was approved, so it seems that this side-effect-free style is preferred for Range* examples. This PR performs the same translation for `RangeFrom` and `RangeInclusive`. It also removes what looks to be an erroneously commented line for `#![feature(step_by)]`, and an unnecessary primitive-type annotation in `0u8..`. add `fn main` wrappers to enable Rust Playground "Run" button
2016-08-24Use `#[prelude_import]` in `libcore`.Jeffrey Seyfried-27/+4
2016-08-23Auto merge of #35656 - Stebalien:fused, r=alexcrichtonbors-8/+173
Implement 1581 (FusedIterator) * [ ] Implement on patterns. See https://github.com/rust-lang/rust/issues/27721#issuecomment-239638642. * [ ] Handle OS Iterators. A bunch of iterators (`Args`, `Env`, etc.) in libstd wrap platform specific iterators. The current ones all appear to be well-behaved but can we assume that future ones will be? * [ ] Does someone want to audit this? On first glance, all of the iterators on which I implemented `FusedIterator` appear to be well-behaved but there are a *lot* of them so a second pair of eyes would be nice. * I haven't touched rustc internal iterators (or the internal rand) because rustc doesn't actually call `fuse()`. * `FusedIterator` can't be implemented on `std::io::{Bytes, Chars}`. Closes: #35602 (Tracking Issue) Implements: rust-lang/rfcs#1581
2016-08-21Added #![feature] declarationsphilipp-0/+2
2016-08-20Introduce max_by/min_by on iteratorsphilipp-0/+51
2016-08-19std: Stabilize APIs for the 1.12 releaseAlex Crichton-10/+12
Stabilized * `Cell::as_ptr` * `RefCell::as_ptr` * `IpAddr::is_{unspecified,loopback,multicast}` * `Ipv6Addr::octets` * `LinkedList::contains` * `VecDeque::contains` * `ExitStatusExt::from_raw` - both on Unix and Windows * `Receiver::recv_timeout` * `RecvTimeoutError` * `BinaryHeap::peek_mut` * `PeekMut` * `iter::Product` * `iter::Sum` * `OccupiedEntry::remove_entry` * `VacantEntry::into_key` Deprecated * `Cell::as_unsafe_cell` * `RefCell::as_unsafe_cell` * `OccupiedEntry::remove_pair` Closes #27708 cc #27709 Closes #32313 Closes #32630 Closes #32713 Closes #34029 Closes #34392 Closes #34285 Closes #34529
2016-08-18Add a FusedIterator trait.Steven Allen-8/+173
This trait can be used to avoid the overhead of a fuse wrapper when an iterator is already well-behaved. Conforming to: RFC 1581 Closes: #35602
2016-08-15remove `.take(10)` from `Range` exampleMatthew Piziak-1/+1
2016-08-15accumulate into vector and assert, instead of printingMatthew Piziak-15/+2
I'm only making this change in one place so that people can express their preferences for this stylistic change. If/when this change is approved I'll go ahead and translate the rest of the `std::ops` examples.
2016-08-06Indicate tracking issue for `exact_size_is_empty` unstability.Corey Farwell-1/+1
2016-07-26Rollup merge of #34732 - durka:patch-27, r=steveklabnikSteve Klabnik-3/+4
document DoubleEndedIterator::next_back document DoubleEndedIterator::next_back fixes #34726
2016-07-18Auto merge of #34357 - tbu-:pr_exact_size_is_empty, r=brsonbors-2/+28
Add `is_empty` function to `ExactSizeIterator` All other types implementing a `len` functions have `is_empty` already.
2016-07-18Fix doctest of `ExactSizeIterator::is_empty`Tobias Bucher-1/+3
2016-07-12std: Clean out deprecated APIsAlex Crichton-33/+0
This primarily removes a lot of `sync::Static*` APIs and rejiggers the associated implementations. While doing this it was discovered that the `is_poisoned` method can actually result in a data race for the Mutex/RwLock primitives, so the inner `Cell<bool>` was changed to an `AtomicBool` to prevent the associated data race. Otherwise the usage/gurantees should be the same they were before.
2016-07-08document DoubleEndedIterator::next_backAlex Burka-3/+4
fixes #34726
2016-07-08Rollup merge of #34688 - GuillaumeGomez:double_ended_iterator, r=steveklabnikManish Goregaokar-6/+12
Improve DoubleEndedIterator examples Fixes #34065. r? @steveklabnik
2016-07-06Rollup merge of #33265 - tshepang:peek, r=steveklabnikSteve Klabnik-11/+9
doc: some `peek` improvements
2016-07-06Improve DoubleEndedIterator examplesGuillaume Gomez-6/+12
2016-07-03std: Stabilize APIs for the 1.11.0 releaseAlex Crichton-58/+267
Although the set of APIs being stabilized this release is relatively small, the trains keep going! Listed below are the APIs in the standard library which have either transitioned from unstable to stable or those from unstable to deprecated. Stable * `BTreeMap::{append, split_off}` * `BTreeSet::{append, split_off}` * `Cell::get_mut` * `RefCell::get_mut` * `BinaryHeap::append` * `{f32, f64}::{to_degrees, to_radians}` - libcore stabilizations mirroring past libstd stabilizations * `Iterator::sum` * `Iterator::product` Deprecated * `{f32, f64}::next_after` * `{f32, f64}::integer_decode` * `{f32, f64}::ldexp` * `{f32, f64}::frexp` * `num::One` * `num::Zero` Added APIs (all unstable) * `iter::Sum` * `iter::Product` * `iter::Step` - a few methods were added to accomodate deprecation of One/Zero Removed APIs * `From<Range<T>> for RangeInclusive<T>` - everything about `RangeInclusive` is unstable Closes #27739 Closes #27752 Closes #32526 Closes #33444 Closes #34152 cc #34529 (new tracking issue)
2016-06-21Auto merge of #34155 - ollie27:unzip, r=alexcrichtonbors-15/+0
Remove unzip() SizeHint hack This was using an invalid iterator so is likely to end with buggy behaviour. It also doesn't even benefit many type in std including Vec so removing it shouldn't cause any problems. Fixes: #33468
2016-06-19Remove first empty line of doc commentTobias Bucher-1/+0
2016-06-19Add `is_empty` function to `ExactSizeIterator`Tobias Bucher-2/+27
All other types implementing a `len` functions have `is_empty` already.