6071 Commits

Author SHA1 Message Date
bors
81601cd3a3 Auto merge of #37306 - bluss:trusted-len, r=alexcrichton
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-04 10:40:30 -07:00
Ulrik Sverdrup
f0e6b90790 Link the tracking issue for TrustedLen 2016-11-04 01:00:55 +01:00
Jonathan Turner
0befab2343 Rollup merge of #37523 - d-unseductable:deref_mut_lifetimes, r=bluss
Elide lifetimes in DerefMut documentation

 - Elide lifetimes to increase the readability of `DerefMut` examples
2016-11-02 15:09:43 -04:00
Jonathan Turner
805aecc36a Rollup merge of #37517 - Mark-Simulacrum:add-unwrap-default-tracking-issue, r=alexcrichton
Add tracking issue number to Result::unwrap_or_default unstable annotation.

Implemented in https://github.com/rust-lang/rust/pull/37299.

Tracking issue: https://github.com/rust-lang/rust/issues/37516.
2016-11-02 15:09:42 -04:00
Jonathan Turner
3752673cbc Rollup merge of #37473 - joshtriplett:doc-copyedit-write-writeln, r=alexcrichton
Copyediting on documentation for write! and writeln!

Fix various sentence fragments, missing articles, and other grammatical issues in the documentation for write! and writeln!.

Also fix the links (and link names) for common return types.

(Noticed when preparing https://github.com/rust-lang/rust/pull/37472 ; posted separately to avoid mixing the new documentation with copyedits to existing documentation.)
2016-11-02 15:09:41 -04:00
Jonathan Turner
d00e5e9343 Rollup merge of #37351 - Amanieu:consume, r=alexcrichton
Prevent exhaustive matching of Ordering to allow for future extension

The C++11 atomic memory model defines a `memory_order_consume` ordering which is generally equivalent to `memory_order_acquire` but can allow better code generation by avoiding memory barrier instructions. Most compilers (including LLVM) currently do not implement this ordering directly and instead treat it identically to `memory_order_acquire`, including adding a memory barrier instruction.

There is currently [work](http://open-std.org/Jtc1/sc22/wg21/docs/papers/2016/p0098r1.pdf) to support consume ordering in compilers, and it would be a shame if Rust did not support this. This PR therefore reserves a `__Nonexhaustive` variant in `Ordering` so that adding a new ordering is not a breaking change in the future.

This is a [breaking-change] since it disallows exhaustive matching on `Ordering`, however a search of all Rust code on Github shows that there is no code that does this. This makes sense since `Ordering` is typically only used as a parameter to an atomic operation.
2016-11-02 15:09:41 -04:00
bors
acfe959701 Auto merge of #37054 - rednum:master, r=alexcrichton
Add or and or_else for ordering.

Fixes https://github.com/rust-lang/rust/issues/37053 (see discussion in rust-lang/rfcs#1677).
2016-11-02 05:37:33 -07:00
Dmitry Gritsay
7d5b788edf Elide lifetimes in DerefMut documentation
- Elide lifetimes to increase the readability
   of `DerefMut` examples
2016-11-01 23:18:02 +02:00
Mark-Simulacrum
6720e0191c Add tracking issue number to Result::unwrap_or_default unstable annotation. 2016-11-01 09:47:09 -06:00
Guillaume Gomez
7e805eae8e Rollup merge of #37316 - ollie27:docs_links, r=GuillaumeGomez
Fix a few links in the docs

r? @steveklabnik
2016-11-01 16:15:52 +01:00
Guillaume Gomez
79d3d26c2e Rollup merge of #36849 - diwic:69-fromutf8-doc, r=alexcrichton
str: Fix documentation typo

from_utf8 returns a Result, not an Option.

Signed-off-by: David Henningsson diwic@ubuntu.com
2016-11-01 16:15:51 +01:00
Marcin Fatyga
655effedf2 Merge branch 'master' of https://github.com/rust-lang/rust
Conflicts:
	src/libcoretest/lib.rs
2016-11-01 15:26:22 +01:00
bors
ac968c4664 Auto merge of #37299 - devonhollowood:result-unwrap-or-default, r=alexcrichton
Add `unwrap_or_default` method to `Result`

Fixes #37025
2016-11-01 03:53:42 -07:00
iirelu
e593c3b893 Changed most vec! invocations to use square braces
Most of the Rust community agrees that the vec! macro is clearer when
called using square brackets [] instead of regular brackets (). Most of
these ocurrences are from before macros allowed using different types of
brackets.

There is one left unchanged in a pretty-print test, as the pretty
printer still wants it to have regular brackets.
2016-10-31 22:51:40 +00:00
Guillaume Gomez
0a59eba0e8 Rollup merge of #37486 - msiglreith:pr_doc_bitandassign, r=apasel422
Fix typo in the BitAndAssign operator documentation

The name of the operator should be `&=` instead of `&`.
2016-10-31 12:27:24 +01:00
Guillaume Gomez
48def35f1b Rollup merge of #37438 - Cobrand:index_doc, r=GuillaumeGomez
improve docs for Index and IndexMut

This mainly changes the boring example of Foo/Bar of `IndexMut` into a better one.

Also added explanations about syntactic sugar for `v[index]`.

Closes #36329
2016-10-31 12:27:23 +01:00
msiglreith
9802c4c5f4 Fix typo in the BitAndAssign operator documentation 2016-10-30 17:50:28 +01:00
Josh Triplett
07bff08e4f Copyediting on documentation for write! and writeln!
Fix various sentence fragments, missing articles, and other grammatical
issues in the documentation for write! and writeln!.

Also fix the links (and link names) for common return types.
2016-10-29 15:44:43 -07:00
Cobrand
6768edde78 improve docs for Index and IndexMut 2016-10-28 17:18:48 +02:00
Tamir Duberstein
bef1911b15
tidy/features: fix checking of lang features
Removes the `STATUSES` static which duplicates truth from the pattern
match in `collect_lang_features`.

Fixes existing duplicates by renaming:
- never_type{,_impls} on `impl`s on `!`
- concat_idents{,_macro} on `macro_rules! concat_idents`

Fixes #37013.
2016-10-27 21:35:57 -04:00
Marcin Fatyga
4e2822c5c2 Rename ordering chaining functions. 2016-10-27 23:31:10 +02:00
bors
3a25b65c1f Auto merge of #37315 - bluss:fold-more, r=alexcrichton
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-26 11:43:32 -07:00
bors
a5b6a9fa8a Auto merge of #37312 - arthurprs:sip-smaller, r=alexcrichton
Small improvement to SipHasher

Very small but constant improvement, the objective is to lower latency for u16, u32 and small strings.

CC #35735

```
➜  siphash-bench git:(master) ✗ sudo nice -n -20 target/release/foo-648738a54f390643 --bench | tee benches.txt
[sudo] password for arthurprs:

running 62 tests
test _same                       ... bench:           0 ns/iter (+/- 0)
test _warmup                     ... bench:           0 ns/iter (+/- 0)
test rust_siphash13::int_u16     ... bench:          12 ns/iter (+/- 1)
test rust_siphash13::int_u32     ... bench:          14 ns/iter (+/- 0)
test rust_siphash13::int_u64     ... bench:          11 ns/iter (+/- 1)
test rust_siphash13::int_u8      ... bench:          11 ns/iter (+/- 1)
test rust_siphash13::slice::_10  ... bench:          18 ns/iter (+/- 1)
test rust_siphash13::slice::_100 ... bench:          42 ns/iter (+/- 2)
test rust_siphash13::slice::_11  ... bench:          19 ns/iter (+/- 1)
test rust_siphash13::slice::_12  ... bench:          21 ns/iter (+/- 3)
test rust_siphash13::slice::_2   ... bench:          16 ns/iter (+/- 2)
test rust_siphash13::slice::_200 ... bench:          68 ns/iter (+/- 3)
test rust_siphash13::slice::_3   ... bench:          17 ns/iter (+/- 3)
test rust_siphash13::slice::_4   ... bench:          18 ns/iter (+/- 1)
test rust_siphash13::slice::_5   ... bench:          19 ns/iter (+/- 4)
test rust_siphash13::slice::_6   ... bench:          19 ns/iter (+/- 1)
test rust_siphash13::slice::_7   ... bench:          20 ns/iter (+/- 1)
test rust_siphash13::slice::_8   ... bench:          16 ns/iter (+/- 1)
test rust_siphash13::slice::_9   ... bench:          18 ns/iter (+/- 2)
test rust_siphash13::str_::_10   ... bench:          18 ns/iter (+/- 1)
test rust_siphash13::str_::_100  ... bench:          41 ns/iter (+/- 2)
test rust_siphash13::str_::_11   ... bench:          19 ns/iter (+/- 1)
test rust_siphash13::str_::_12   ... bench:          20 ns/iter (+/- 2)
test rust_siphash13::str_::_2    ... bench:          16 ns/iter (+/- 1)
test rust_siphash13::str_::_200  ... bench:          68 ns/iter (+/- 3)
test rust_siphash13::str_::_3    ... bench:          17 ns/iter (+/- 1)
test rust_siphash13::str_::_4    ... bench:          18 ns/iter (+/- 2)
test rust_siphash13::str_::_5    ... bench:          19 ns/iter (+/- 6)
test rust_siphash13::str_::_6    ... bench:          20 ns/iter (+/- 5)
test rust_siphash13::str_::_7    ... bench:          23 ns/iter (+/- 1)
test rust_siphash13::str_::_8    ... bench:          15 ns/iter (+/- 1)
test rust_siphash13::str_::_9    ... bench:          17 ns/iter (+/- 1)
test sip1b::int_u16              ... bench:          10 ns/iter (+/- 1)
test sip1b::int_u32              ... bench:           9 ns/iter (+/- 1)
test sip1b::int_u64              ... bench:          12 ns/iter (+/- 1)
test sip1b::int_u8               ... bench:           7 ns/iter (+/- 0)
test sip1b::slice::_10           ... bench:          12 ns/iter (+/- 1)
test sip1b::slice::_100          ... bench:          33 ns/iter (+/- 2)
test sip1b::slice::_11           ... bench:          13 ns/iter (+/- 0)
test sip1b::slice::_12           ... bench:          12 ns/iter (+/- 1)
test sip1b::slice::_2            ... bench:          10 ns/iter (+/- 0)
test sip1b::slice::_200          ... bench:          62 ns/iter (+/- 2)
test sip1b::slice::_3            ... bench:          10 ns/iter (+/- 1)
test sip1b::slice::_4            ... bench:           9 ns/iter (+/- 0)
test sip1b::slice::_5            ... bench:          10 ns/iter (+/- 1)
test sip1b::slice::_6            ... bench:          10 ns/iter (+/- 0)
test sip1b::slice::_7            ... bench:          11 ns/iter (+/- 0)
test sip1b::slice::_8            ... bench:          11 ns/iter (+/- 1)
test sip1b::slice::_9            ... bench:          12 ns/iter (+/- 1)
test sip1b::str_::_10            ... bench:          15 ns/iter (+/- 1)
test sip1b::str_::_100           ... bench:          37 ns/iter (+/- 3)
test sip1b::str_::_11            ... bench:          16 ns/iter (+/- 1)
test sip1b::str_::_12            ... bench:          14 ns/iter (+/- 1)
test sip1b::str_::_2             ... bench:          13 ns/iter (+/- 1)
test sip1b::str_::_200           ... bench:          67 ns/iter (+/- 5)
test sip1b::str_::_3             ... bench:          14 ns/iter (+/- 2)
test sip1b::str_::_4             ... bench:          12 ns/iter (+/- 1)
test sip1b::str_::_5             ... bench:          13 ns/iter (+/- 1)
test sip1b::str_::_6             ... bench:          13 ns/iter (+/- 0)
test sip1b::str_::_7             ... bench:          16 ns/iter (+/- 1)
test sip1b::str_::_8             ... bench:          14 ns/iter (+/- 1)
test sip1b::str_::_9             ... bench:          15 ns/iter (+/- 1)

test result: ok. 0 passed; 0 failed; 0 ignored; 62 measured

➜  siphash-bench git:(master) ✗ cargo benchcmp rust_siphash13:: sip1b:: benches.txt
 name         rust_siphash13:: ns/iter  sip1b:: ns/iter  diff ns/iter   diff %
 int_u16      12                        10                         -2  -16.67%
 int_u32      14                        9                          -5  -35.71%
 int_u64      11                        12                          1    9.09%
 int_u8       11                        7                          -4  -36.36%
 slice::_10   18                        12                         -6  -33.33%
 slice::_100  42                        33                         -9  -21.43%
 slice::_11   19                        13                         -6  -31.58%
 slice::_12   21                        12                         -9  -42.86%
 slice::_2    16                        10                         -6  -37.50%
 slice::_200  68                        62                         -6   -8.82%
 slice::_3    17                        10                         -7  -41.18%
 slice::_4    18                        9                          -9  -50.00%
 slice::_5    19                        10                         -9  -47.37%
 slice::_6    19                        10                         -9  -47.37%
 slice::_7    20                        11                         -9  -45.00%
 slice::_8    16                        11                         -5  -31.25%
 slice::_9    18                        12                         -6  -33.33%
 str_::_10    18                        15                         -3  -16.67%
 str_::_100   41                        37                         -4   -9.76%
 str_::_11    19                        16                         -3  -15.79%
 str_::_12    20                        14                         -6  -30.00%
 str_::_2     16                        13                         -3  -18.75%
 str_::_200   68                        67                         -1   -1.47%
 str_::_3     17                        14                         -3  -17.65%
 str_::_4     18                        12                         -6  -33.33%
 str_::_5     19                        13                         -6  -31.58%
 str_::_6     20                        13                         -7  -35.00%
 str_::_7     23                        16                         -7  -30.43%
 str_::_8     15                        14                         -1   -6.67%
 str_::_9     17                        15                         -2  -11.76%

```

from a modified hash-rs suite (preallocating maps and adding having slice/str variants)

graph version: http://imgur.com/a/DuoI4

```
➜  hash-rs git:(rfc-extend-hasher) ✗ cargo benchcmp sip13:: sip13opt:: benches.txt
 name                             sip13:: ns/iter      sip13opt:: ns/iter   diff ns/iter   diff %
 slice::mapcountdense_000000001   27,343 (36 MB/s)     26,401 (37 MB/s)             -942   -3.45%
 slice::mapcountdense_000000002   28,982 (69 MB/s)     26,807 (74 MB/s)           -2,175   -7.50%
 slice::mapcountdense_000000003   29,304 (102 MB/s)    27,360 (109 MB/s)          -1,944   -6.63%
 slice::mapcountdense_000000004   30,411 (131 MB/s)    25,888 (154 MB/s)          -4,523  -14.87%
 slice::mapcountdense_000000005   32,625 (153 MB/s)    27,486 (181 MB/s)          -5,139  -15.75%
 slice::mapcountdense_000000006   34,920 (171 MB/s)    27,204 (220 MB/s)          -7,716  -22.10%
 slice::mapcountdense_000000007   33,497 (208 MB/s)    28,330 (247 MB/s)          -5,167  -15.43%
 slice::mapcountdense_000000008   31,153 (256 MB/s)    28,617 (279 MB/s)          -2,536   -8.14%
 slice::mapcountdense_000000009   30,745 (292 MB/s)    29,666 (303 MB/s)          -1,079   -3.51%
 slice::mapcountdense_000000010   31,509 (317 MB/s)    29,804 (335 MB/s)          -1,705   -5.41%
 slice::mapcountdense_000000011   32,526 (338 MB/s)    30,520 (360 MB/s)          -2,006   -6.17%
 slice::mapcountdense_000000012   32,981 (363 MB/s)    28,739 (417 MB/s)          -4,242  -12.86%
 slice::mapcountdense_000000013   34,713 (374 MB/s)    30,348 (428 MB/s)          -4,365  -12.57%
 slice::mapcountdense_000000014   34,635 (404 MB/s)    29,974 (467 MB/s)          -4,661  -13.46%
 slice::mapcountdense_000000015   35,924 (417 MB/s)    30,584 (490 MB/s)          -5,340  -14.86%
 slice::mapcountdense_000000016   31,939 (500 MB/s)    30,564 (523 MB/s)          -1,375   -4.31%
 slice::mapcountdense_000000032   36,545 (875 MB/s)    34,833 (918 MB/s)          -1,712   -4.68%
 slice::mapcountdense_000000064   44,691 (1432 MB/s)   43,912 (1457 MB/s)           -779   -1.74%
 slice::mapcountdense_000000128   67,210 (1904 MB/s)   64,630 (1980 MB/s)         -2,580   -3.84%
 slice::mapcountdense_000000256   110,320 (2320 MB/s)  108,713 (2354 MB/s)        -1,607   -1.46%
 slice::mapcountsparse_000000001  29,686 (33 MB/s)     28,673 (34 MB/s)           -1,013   -3.41%
 slice::mapcountsparse_000000002  32,073 (62 MB/s)     30,519 (65 MB/s)           -1,554   -4.85%
 slice::mapcountsparse_000000003  33,184 (90 MB/s)     31,208 (96 MB/s)           -1,976   -5.95%
 slice::mapcountsparse_000000004  34,344 (116 MB/s)    30,242 (132 MB/s)          -4,102  -11.94%
 slice::mapcountsparse_000000005  34,536 (144 MB/s)    30,552 (163 MB/s)          -3,984  -11.54%
 slice::mapcountsparse_000000006  35,791 (167 MB/s)    30,813 (194 MB/s)          -4,978  -13.91%
 slice::mapcountsparse_000000007  36,773 (190 MB/s)    31,362 (223 MB/s)          -5,411  -14.71%
 slice::mapcountsparse_000000008  33,101 (241 MB/s)    32,399 (246 MB/s)            -702   -2.12%
 slice::mapcountsparse_000000009  34,025 (264 MB/s)    33,065 (272 MB/s)            -960   -2.82%
 slice::mapcountsparse_000000010  34,755 (287 MB/s)    33,152 (301 MB/s)          -1,603   -4.61%
 slice::mapcountsparse_000000011  35,682 (308 MB/s)    33,631 (327 MB/s)          -2,051   -5.75%
 slice::mapcountsparse_000000012  36,422 (329 MB/s)    32,604 (368 MB/s)          -3,818  -10.48%
 slice::mapcountsparse_000000013  37,561 (346 MB/s)    32,978 (394 MB/s)          -4,583  -12.20%
 slice::mapcountsparse_000000014  38,476 (363 MB/s)    33,376 (419 MB/s)          -5,100  -13.26%
 slice::mapcountsparse_000000015  39,202 (382 MB/s)    33,750 (444 MB/s)          -5,452  -13.91%
 slice::mapcountsparse_000000016  34,898 (458 MB/s)    33,621 (475 MB/s)          -1,277   -3.66%
 slice::mapcountsparse_000000032  39,767 (804 MB/s)    38,013 (841 MB/s)          -1,754   -4.41%
 slice::mapcountsparse_000000064  47,810 (1338 MB/s)   46,332 (1381 MB/s)         -1,478   -3.09%
 slice::mapcountsparse_000000128  64,519 (1983 MB/s)   63,322 (2021 MB/s)         -1,197   -1.86%
 slice::mapcountsparse_000000256  101,042 (2533 MB/s)  99,754 (2566 MB/s)         -1,288   -1.27%
 str_::mapcountdense_000000001    27,183 (36 MB/s)     24,007 (41 MB/s)           -3,176  -11.68%
 str_::mapcountdense_000000002    28,940 (69 MB/s)     24,574 (81 MB/s)           -4,366  -15.09%
 str_::mapcountdense_000000003    29,000 (103 MB/s)    24,687 (121 MB/s)          -4,313  -14.87%
 str_::mapcountdense_000000004    29,822 (134 MB/s)    24,377 (164 MB/s)          -5,445  -18.26%
 str_::mapcountdense_000000005    31,962 (156 MB/s)    25,184 (198 MB/s)          -6,778  -21.21%
 str_::mapcountdense_000000006    32,218 (186 MB/s)    25,020 (239 MB/s)          -7,198  -22.34%
 str_::mapcountdense_000000007    35,482 (197 MB/s)    27,705 (252 MB/s)          -7,777  -21.92%
 str_::mapcountdense_000000008    28,643 (279 MB/s)    25,563 (312 MB/s)          -3,080  -10.75%
 str_::mapcountdense_000000009    30,112 (298 MB/s)    26,773 (336 MB/s)          -3,339  -11.09%
 str_::mapcountdense_000000010    31,554 (316 MB/s)    27,607 (362 MB/s)          -3,947  -12.51%
 str_::mapcountdense_000000011    32,062 (343 MB/s)    27,770 (396 MB/s)          -4,292  -13.39%
 str_::mapcountdense_000000012    32,258 (372 MB/s)    25,612 (468 MB/s)          -6,646  -20.60%
 str_::mapcountdense_000000013    33,544 (387 MB/s)    26,908 (483 MB/s)          -6,636  -19.78%
 str_::mapcountdense_000000014    34,681 (403 MB/s)    27,267 (513 MB/s)          -7,414  -21.38%
 str_::mapcountdense_000000015    37,883 (395 MB/s)    30,226 (496 MB/s)          -7,657  -20.21%
 str_::mapcountdense_000000016    30,299 (528 MB/s)    27,960 (572 MB/s)          -2,339   -7.72%
 str_::mapcountdense_000000032    34,372 (930 MB/s)    32,736 (977 MB/s)          -1,636   -4.76%
 str_::mapcountdense_000000048    38,610 (1243 MB/s)   36,437 (1317 MB/s)         -2,173   -5.63%
 str_::mapcountdense_000000064    43,052 (1486 MB/s)   41,269 (1550 MB/s)         -1,783   -4.14%
 str_::mapcountdense_000000128    64,059 (1998 MB/s)   62,007 (2064 MB/s)         -2,052   -3.20%
 str_::mapcountdense_000000256    109,608 (2335 MB/s)  107,184 (2388 MB/s)        -2,424   -2.21%
 str_::mapcountsparse_000000001   29,155 (34 MB/s)     26,151 (38 MB/s)           -3,004  -10.30%
 str_::mapcountsparse_000000002   31,536 (63 MB/s)     27,787 (71 MB/s)           -3,749  -11.89%
 str_::mapcountsparse_000000003   32,524 (92 MB/s)     27,861 (107 MB/s)          -4,663  -14.34%
 str_::mapcountsparse_000000004   33,535 (119 MB/s)    27,585 (145 MB/s)          -5,950  -17.74%
 str_::mapcountsparse_000000005   34,239 (146 MB/s)    27,520 (181 MB/s)          -6,719  -19.62%
 str_::mapcountsparse_000000006   35,485 (169 MB/s)    27,437 (218 MB/s)          -8,048  -22.68%
 str_::mapcountsparse_000000007   39,098 (179 MB/s)    30,465 (229 MB/s)          -8,633  -22.08%
 str_::mapcountsparse_000000008   30,882 (259 MB/s)    29,215 (273 MB/s)          -1,667   -5.40%
 str_::mapcountsparse_000000009   33,375 (269 MB/s)    29,301 (307 MB/s)          -4,074  -12.21%
 str_::mapcountsparse_000000010   33,531 (298 MB/s)    29,008 (344 MB/s)          -4,523  -13.49%
 str_::mapcountsparse_000000011   34,607 (317 MB/s)    29,800 (369 MB/s)          -4,807  -13.89%
 str_::mapcountsparse_000000012   35,700 (336 MB/s)    28,380 (422 MB/s)          -7,320  -20.50%
 str_::mapcountsparse_000000013   36,692 (354 MB/s)    29,350 (442 MB/s)          -7,342  -20.01%
 str_::mapcountsparse_000000014   37,326 (375 MB/s)    29,285 (478 MB/s)          -8,041  -21.54%
 str_::mapcountsparse_000000015   41,098 (364 MB/s)    33,073 (453 MB/s)          -8,025  -19.53%
 str_::mapcountsparse_000000016   33,046 (484 MB/s)    30,717 (520 MB/s)          -2,329   -7.05%
 str_::mapcountsparse_000000032   37,471 (853 MB/s)    35,542 (900 MB/s)          -1,929   -5.15%
 str_::mapcountsparse_000000048   41,324 (1161 MB/s)   39,332 (1220 MB/s)         -1,992   -4.82%
 str_::mapcountsparse_000000064   45,858 (1395 MB/s)   43,802 (1461 MB/s)         -2,056   -4.48%
 str_::mapcountsparse_000000128   62,471 (2048 MB/s)   60,683 (2109 MB/s)         -1,788   -2.86%
 str_::mapcountsparse_000000256   101,283 (2527 MB/s)  97,655 (2621 MB/s)         -3,628   -3.58%
```
2016-10-26 08:15:07 -07:00
bors
a6b3b01b5f Auto merge of #37270 - Mark-Simulacrum:smallvec-optimized-arenas, r=eddyb
Add ArrayVec and AccumulateVec to reduce heap allocations during interning of slices

Updates `mk_tup`, `mk_type_list`, and `mk_substs` to allow interning directly from iterators. The previous PR, #37220, changed some of the calls to pass a borrowed slice from `Vec` instead of directly passing the iterator, and these changes further optimize that to avoid the allocation entirely.

This change yields 50% less malloc calls in [some cases](https://pastebin.mozilla.org/8921686). It also yields decent, though not amazing, performance improvements:
```
futures-rs-test  4.091s vs  4.021s --> 1.017x faster (variance: 1.004x, 1.004x)
helloworld       0.219s vs  0.220s --> 0.993x faster (variance: 1.010x, 1.018x)
html5ever-2016-  3.805s vs  3.736s --> 1.018x faster (variance: 1.003x, 1.009x)
hyper.0.5.0      4.609s vs  4.571s --> 1.008x faster (variance: 1.015x, 1.017x)
inflate-0.1.0    3.864s vs  3.883s --> 0.995x faster (variance: 1.232x, 1.005x)
issue-32062-equ  0.309s vs  0.299s --> 1.033x faster (variance: 1.014x, 1.003x)
issue-32278-big  1.614s vs  1.594s --> 1.013x faster (variance: 1.007x, 1.004x)
jld-day15-parse  1.390s vs  1.326s --> 1.049x faster (variance: 1.006x, 1.009x)
piston-image-0. 10.930s vs 10.675s --> 1.024x faster (variance: 1.006x, 1.010x)
reddit-stress    2.302s vs  2.261s --> 1.019x faster (variance: 1.010x, 1.026x)
regex.0.1.30     2.250s vs  2.240s --> 1.005x faster (variance: 1.087x, 1.011x)
rust-encoding-0  1.895s vs  1.887s --> 1.005x faster (variance: 1.005x, 1.018x)
syntex-0.42.2   29.045s vs 28.663s --> 1.013x faster (variance: 1.004x, 1.006x)
syntex-0.42.2-i 13.925s vs 13.868s --> 1.004x faster (variance: 1.022x, 1.007x)
```

We implement a small-size optimized vector, intended to be used primarily for collection of presumed to be short iterators. This vector cannot be "upsized/reallocated" into a heap-allocated vector, since that would require (slow) branching logic, but during the initial collection from an iterator heap-allocation is possible.

We make the new `AccumulateVec` and `ArrayVec` generic over implementors of the `Array` trait, of which there is currently one, `[T; 8]`. In the future, this is likely to expand to other values of N.

Huge thanks to @nnethercote for collecting the performance and other statistics mentioned above.
2016-10-26 03:47:55 -07:00
Mark-Simulacrum
989eba79a3 Add size hint to Result's FromIterator implementation. 2016-10-25 20:06:17 -06:00
Ulrik Sverdrup
a16626fc42 iter: Implement .fold() for .chain()
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-25 22:06:39 +02:00
arthurprs
a319d13a9b Small improvement to SipHasher 2016-10-25 20:33:03 +02:00
Ulrik Sverdrup
780acda325 iter: Implement .fold() for .cloned() and .map()
Implement .fold() specifically for .map() and .cloned() so that any
inner fold improvements are available through map and cloned.
2016-10-25 15:50:52 +02:00
Amanieu d'Antras
5a2fb8806b Prevent exhaustive matching of Ordering to allow for future extension 2016-10-23 11:56:51 +01:00
bors
87af2324bb Auto merge of #37325 - newpavlov:master, r=frewsxcv
libcore documentation for builtin macros

Fixes: #36272

Additionally I've edited docstring for `include!` a bit. (related PR #36404)

Unfortunately it seems there is no sane way to reexport empty macros definitions for their docstrings. To avoid copying the whole documentation for builtin macros I've only copied description and added links to `std` macro pages.
2016-10-23 02:10:28 -07:00
Marcin Fatyga
634715a736 Actually fix doctests. 2016-10-22 20:43:28 +02:00
Guillaume Gomez
1c2d2235c9 Rollup merge of #37314 - tshepang:simple, r=GuillaumeGomez
doc: a more simple description of Iterator::nth
2016-10-22 01:22:00 +02:00
Guillaume Gomez
8133a55e05 Rollup merge of #37219 - srinivasreddy:prelude, r=nrc
Run rustfmt on libcore/prelude folder
2016-10-22 01:21:59 +02:00
Devon Hollowood
5d31a818df Fix use of result_unwrap_or_default feature 2016-10-21 14:33:20 -07:00
Артём Павлов [Artyom Pavlov]
b374c53ae6
Small doc change for include! 2016-10-21 17:44:19 +03:00
Артём Павлов [Artyom Pavlov]
ce8e4e71f8
libcore documentation for builtin macros 2016-10-21 17:23:50 +03:00
Devon Hollowood
fb1ef4f42c Make Result's unwrap_or_default unstable 2016-10-20 23:50:33 -07:00
Oliver Middleton
8faa503a6b Fix a few links in the docs 2016-10-21 00:49:47 +01:00
Tshepang Lekhonkhobe
3e26a93a36 doc: a more simple description of Iterator::nth 2016-10-21 00:38:00 +02:00
Ulrik Sverdrup
a3cab90fda Document TrustedLen’s contract 2016-10-20 14:44:31 +02:00
Ulrik Sverdrup
69b9400b79 Implement TrustedLen for more iterators 2016-10-20 14:40:09 +02:00
Ulrik Sverdrup
9ae9930e2f Introduce iterator trait TrustedLen 2016-10-20 14:07:06 +02:00
Devon Hollowood
1c2151b7f9 Add unwrap_or_default method to Result 2016-10-19 22:08:49 -07:00
Eduard-Mihai Burtescu
3d57d42f13 Rollup merge of #37240 - jethrogb:typeid_doc, r=sfackler
Add stable example to TypeId

The old example is still available at [Any::get_type_id](https://doc.rust-lang.org/std/any/trait.Any.html#examples)
2016-10-19 08:00:03 +03:00
Eduard-Mihai Burtescu
7b0eb102de Rollup merge of #37230 - bluss:zip-specialization-for-map, r=alexcrichton
Expand .zip() specialization to .map() and .cloned()

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-19 08:00:02 +03:00
Jethro Beekman
a29b503033 Add stable example to TypeId 2016-10-17 17:49:07 -07:00
Ulrik Sverdrup
ed5015939f Expand .zip() specialization to .map() and .cloned()
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-17 10:58:21 +02:00
Marcin Fatyga
c78a212110 Add ordering_chaining feature to libcore/lib.rs 2016-10-17 08:37:54 +02:00
Marcin Fatyga
43a022660a Fix doctests 2016-10-16 20:24:20 +02:00
Srinivas Reddy Thatiparthy
7a491bb66d
Run rustfmt on libcore/prelude folder 2016-10-16 22:13:04 +05:30