2014-06-28 15:57:36 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
2015-01-07 20:53:58 -06:00
|
|
|
|
2016-01-30 18:19:37 -06:00
|
|
|
#![deny(warnings)]
|
|
|
|
|
2018-03-12 02:29:06 -05:00
|
|
|
#![feature(ascii_ctype)]
|
2015-01-07 20:53:58 -06:00
|
|
|
#![feature(box_syntax)]
|
2017-06-04 13:39:00 -05:00
|
|
|
#![feature(core_float)]
|
2015-09-20 11:34:33 -05:00
|
|
|
#![feature(core_private_bignum)]
|
|
|
|
#![feature(core_private_diy_float)]
|
2015-08-29 11:30:05 -05:00
|
|
|
#![feature(dec2flt)]
|
2016-05-27 11:16:27 -05:00
|
|
|
#![feature(decode_utf8)]
|
2017-07-06 10:13:29 -05:00
|
|
|
#![feature(exact_size_is_empty)]
|
2015-08-29 11:30:05 -05:00
|
|
|
#![feature(fixed_size_array)]
|
2015-06-10 15:33:52 -05:00
|
|
|
#![feature(flt2dec)]
|
2017-03-17 09:05:44 -05:00
|
|
|
#![feature(fmt_internals)]
|
2017-05-12 13:11:15 -05:00
|
|
|
#![feature(iterator_step_by)]
|
2017-04-23 23:47:09 -05:00
|
|
|
#![feature(i128_type)]
|
2018-01-27 13:19:29 -06:00
|
|
|
#![cfg_attr(stage0, feature(inclusive_range_syntax))]
|
2017-10-23 00:47:27 -05:00
|
|
|
#![feature(iterator_try_fold)]
|
2018-02-13 17:58:14 -06:00
|
|
|
#![feature(iterator_flatten)]
|
|
|
|
#![feature(conservative_impl_trait)]
|
2017-04-07 20:43:18 -05:00
|
|
|
#![feature(iter_rfind)]
|
Add more custom folding to `core::iter` adaptors
Many of the iterator adaptors will perform faster folds if they forward
to their inner iterator's folds, especially for inner types like `Chain`
which are optimized too. The following types are newly specialized:
| Type | `fold` | `rfold` |
| ----------- | ------ | ------- |
| `Enumerate` | ✓ | ✓ |
| `Filter` | ✓ | ✓ |
| `FilterMap` | ✓ | ✓ |
| `FlatMap` | exists | ✓ |
| `Fuse` | ✓ | ✓ |
| `Inspect` | ✓ | ✓ |
| `Peekable` | ✓ | N/A¹ |
| `Skip` | ✓ | N/A² |
| `SkipWhile` | ✓ | N/A¹ |
¹ not a `DoubleEndedIterator`
² `Skip::next_back` doesn't pull skipped items at all, but this couldn't
be avoided if `Skip::rfold` were to call its inner iterator's `rfold`.
Benchmarks
----------
In the following results, plain `_sum` computes the sum of a million
integers -- note that `sum()` is implemented with `fold()`. The
`_ref_sum` variants do the same on a `by_ref()` iterator, which is
limited to calling `next()` one by one, without specialized `fold`.
The `chain` variants perform the same tests on two iterators chained
together, to show a greater benefit of forwarding `fold` internally.
test iter::bench_enumerate_chain_ref_sum ... bench: 2,216,264 ns/iter (+/- 29,228)
test iter::bench_enumerate_chain_sum ... bench: 922,380 ns/iter (+/- 2,676)
test iter::bench_enumerate_ref_sum ... bench: 476,094 ns/iter (+/- 7,110)
test iter::bench_enumerate_sum ... bench: 476,438 ns/iter (+/- 3,334)
test iter::bench_filter_chain_ref_sum ... bench: 2,266,095 ns/iter (+/- 6,051)
test iter::bench_filter_chain_sum ... bench: 745,594 ns/iter (+/- 2,013)
test iter::bench_filter_ref_sum ... bench: 889,696 ns/iter (+/- 1,188)
test iter::bench_filter_sum ... bench: 667,325 ns/iter (+/- 1,894)
test iter::bench_filter_map_chain_ref_sum ... bench: 2,259,195 ns/iter (+/- 353,440)
test iter::bench_filter_map_chain_sum ... bench: 1,223,280 ns/iter (+/- 1,972)
test iter::bench_filter_map_ref_sum ... bench: 611,607 ns/iter (+/- 2,507)
test iter::bench_filter_map_sum ... bench: 611,610 ns/iter (+/- 472)
test iter::bench_fuse_chain_ref_sum ... bench: 2,246,106 ns/iter (+/- 22,395)
test iter::bench_fuse_chain_sum ... bench: 634,887 ns/iter (+/- 1,341)
test iter::bench_fuse_ref_sum ... bench: 444,816 ns/iter (+/- 1,748)
test iter::bench_fuse_sum ... bench: 316,954 ns/iter (+/- 2,616)
test iter::bench_inspect_chain_ref_sum ... bench: 2,245,431 ns/iter (+/- 21,371)
test iter::bench_inspect_chain_sum ... bench: 631,645 ns/iter (+/- 4,928)
test iter::bench_inspect_ref_sum ... bench: 317,437 ns/iter (+/- 702)
test iter::bench_inspect_sum ... bench: 315,942 ns/iter (+/- 4,320)
test iter::bench_peekable_chain_ref_sum ... bench: 2,243,585 ns/iter (+/- 12,186)
test iter::bench_peekable_chain_sum ... bench: 634,848 ns/iter (+/- 1,712)
test iter::bench_peekable_ref_sum ... bench: 444,808 ns/iter (+/- 480)
test iter::bench_peekable_sum ... bench: 317,133 ns/iter (+/- 3,309)
test iter::bench_skip_chain_ref_sum ... bench: 1,778,734 ns/iter (+/- 2,198)
test iter::bench_skip_chain_sum ... bench: 761,850 ns/iter (+/- 1,645)
test iter::bench_skip_ref_sum ... bench: 478,207 ns/iter (+/- 119,252)
test iter::bench_skip_sum ... bench: 315,614 ns/iter (+/- 3,054)
test iter::bench_skip_while_chain_ref_sum ... bench: 2,486,370 ns/iter (+/- 4,845)
test iter::bench_skip_while_chain_sum ... bench: 633,915 ns/iter (+/- 5,892)
test iter::bench_skip_while_ref_sum ... bench: 666,926 ns/iter (+/- 804)
test iter::bench_skip_while_sum ... bench: 444,405 ns/iter (+/- 571)
2017-09-25 22:53:08 -05:00
|
|
|
#![feature(iter_rfold)]
|
2018-02-12 02:13:47 -06:00
|
|
|
#![feature(iterator_repeat_with)]
|
2015-06-10 15:33:52 -05:00
|
|
|
#![feature(nonzero)]
|
2017-12-17 16:44:03 -06:00
|
|
|
#![feature(pattern)]
|
2018-02-09 03:47:18 -06:00
|
|
|
#![feature(range_is_empty)]
|
2015-06-10 15:33:52 -05:00
|
|
|
#![feature(raw)]
|
2017-07-31 12:14:16 -05:00
|
|
|
#![feature(refcell_replace_swap)]
|
2016-06-21 16:27:15 -05:00
|
|
|
#![feature(sip_hash_13)]
|
2015-06-10 15:33:52 -05:00
|
|
|
#![feature(slice_patterns)]
|
2017-03-20 20:38:03 -05:00
|
|
|
#![feature(sort_internals)]
|
2017-05-23 04:24:25 -05:00
|
|
|
#![feature(specialization)]
|
2017-04-23 23:47:09 -05:00
|
|
|
#![feature(step_trait)]
|
2015-06-10 15:33:52 -05:00
|
|
|
#![feature(test)]
|
2017-05-23 04:24:25 -05:00
|
|
|
#![feature(trusted_len)]
|
2016-07-27 05:10:31 -05:00
|
|
|
#![feature(try_from)]
|
2017-06-07 22:52:13 -05:00
|
|
|
#![feature(try_trait)]
|
2018-01-11 04:13:45 -06:00
|
|
|
#![feature(exact_chunks)]
|
2018-02-09 12:19:52 -06:00
|
|
|
#![feature(atomic_nand)]
|
2018-02-26 22:34:55 -06:00
|
|
|
#![feature(reverse_bits)]
|
2014-06-28 15:57:36 -05:00
|
|
|
|
|
|
|
extern crate core;
|
|
|
|
extern crate test;
|
2018-02-26 11:07:16 -06:00
|
|
|
extern crate rand;
|
2014-06-28 15:57:36 -05:00
|
|
|
|
|
|
|
mod any;
|
2015-08-29 11:30:05 -05:00
|
|
|
mod array;
|
2018-03-08 21:55:54 -06:00
|
|
|
mod ascii;
|
2014-08-04 17:42:36 -05:00
|
|
|
mod atomic;
|
2014-06-28 15:57:36 -05:00
|
|
|
mod cell;
|
|
|
|
mod char;
|
2015-10-15 14:07:20 -05:00
|
|
|
mod clone;
|
2014-06-28 15:57:36 -05:00
|
|
|
mod cmp;
|
|
|
|
mod fmt;
|
2014-12-12 20:43:07 -06:00
|
|
|
mod hash;
|
2015-10-15 14:07:20 -05:00
|
|
|
mod intrinsics;
|
2014-06-28 15:57:36 -05:00
|
|
|
mod iter;
|
|
|
|
mod mem;
|
2014-12-23 14:52:02 -06:00
|
|
|
mod nonzero;
|
2014-06-28 15:57:36 -05:00
|
|
|
mod num;
|
|
|
|
mod ops;
|
|
|
|
mod option;
|
2017-12-17 16:44:03 -06:00
|
|
|
mod pattern;
|
2014-06-28 15:57:36 -05:00
|
|
|
mod ptr;
|
|
|
|
mod result;
|
2014-08-06 22:48:25 -05:00
|
|
|
mod slice;
|
2014-08-18 20:43:43 -05:00
|
|
|
mod str;
|
2014-06-28 15:57:36 -05:00
|
|
|
mod tuple;
|