Commit Graph

2147 Commits

Author SHA1 Message Date
Ulrik Sverdrup
765700ba7a Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element
Due to missing noalias annotations for &mut T in general (issue #31681),
in larger programs extend_from_slice and extend_with_element may both
compile very poorly. What is observed is that the .set_len() calls are
not lifted out of the loop, even for `Vec<u8>`.

Use a local length variable for the Vec length instead, and use a scope
guard to write this value back to self.len when the scope ends or on
panic. Then the alias analysis is easy.

This affects extend_from_slice, extend_with_element, the vec![x; n]
macro, Write impls for Vec<u8>, BufWriter, etc (but may / may not
have triggered since inlining can be enough for the compiler to get it right).
2016-09-09 02:38:47 +02:00
Jonathan Turner
b5f5f8b865 Rollup merge of #36243 - GuillaumeGomez:hash_map_links, r=steveklabnik
Add missing urls

r? @steveklabnik
2016-09-06 09:38:02 -07:00
Guillaume Gomez
216cf9c124 Add missing urls 2016-09-03 16:15:22 +02:00
bors
01b35d82e5 Auto merge of #36072 - arthurprs:binary_heap_opt, r=Aatch
Optimize BinaryHeap bounds checking

I was experimenting with d-ary binary heaps during the weekend (dead end) and I found that we could get some good improvements by removing bounds checking. Specially due to the panic-safe additional code, llvm can't really optimize them out.

```
 name                         d_ary_heap:: ns/iter  std___heap:: ns/iter  diff ns/iter  diff %
 bench_build_insert           148,610               236,960                     88,350  59.45%
 bench_from_vec               243,846               299,719                     55,873  22.91%
 bench_insert_2000_empty      4,512                 7,517                        3,005  66.60%
 bench_insert_2000_prefilled  28,665                32,605                       3,940  13.74%
 bench_pop_2000               111,515               128,005                     16,490  14.79%
 bench_pop_all                2,759,945             3,317,626                  557,681  20.21%
 peek_mut                     23,186                23,635                         449   1.94%
 pop_modify_push              41,573                43,822                       2,249   5.41%

test d_ary_heap::bench_build_insert          ... bench:     148,610 ns/iter (+/- 10,687)
test d_ary_heap::bench_from_vec              ... bench:     243,846 ns/iter (+/- 16,500)
test d_ary_heap::bench_insert_2000_empty     ... bench:       4,512 ns/iter (+/- 136)
test d_ary_heap::bench_insert_2000_prefilled ... bench:      28,665 ns/iter (+/- 1,347)
test d_ary_heap::bench_pop_2000              ... bench:     111,515 ns/iter (+/- 104,677)
test d_ary_heap::bench_pop_all               ... bench:   2,759,945 ns/iter (+/- 173,838)
test d_ary_heap::peek_mut                    ... bench:      23,186 ns/iter (+/- 106,254)
test d_ary_heap::pop_modify_push             ... bench:      41,573 ns/iter (+/- 3,313)
test std___heap::bench_build_insert          ... bench:     236,960 ns/iter (+/- 16,955)
test std___heap::bench_from_vec              ... bench:     299,719 ns/iter (+/- 6,354)
test std___heap::bench_insert_2000_empty     ... bench:       7,517 ns/iter (+/- 372)
test std___heap::bench_insert_2000_prefilled ... bench:      32,605 ns/iter (+/- 2,433)
test std___heap::bench_pop_2000              ... bench:     128,005 ns/iter (+/- 11,787)
test std___heap::bench_pop_all               ... bench:   3,317,626 ns/iter (+/- 238,968)
test std___heap::peek_mut                    ... bench:      23,635 ns/iter (+/- 1,420)
test std___heap::pop_modify_push             ... bench:      43,822 ns/iter (+/- 3,788)
```

Test code: https://github.com/arthurprs/heap-experiments
2016-09-03 04:40:38 -07:00
Guillaume Gomez
d33e1916ce Rollup merge of #35862 - Stebalien:fmt-docs, r=steveklabnik
Clarify/fix formatting docs concerning fmt::Result/fmt::Error

1. `fmt::Result` != `io::Result<()>`
2. Formatters should only propagate errors, not return their own.

Confusion on reddit: https://www.reddit.com/r/rust/comments/4yorxr/is_implt_tostring_for_t_where_t_display_sized_a/
2016-08-30 10:39:05 +02:00
arthurprs
175d434c99 Remove BinaryHeap bounds checking 2016-08-29 23:12:08 +02:00
bors
eaf71f8d10 Auto merge of #35906 - jseyfried:local_prelude, r=eddyb
Use `#[prelude_import]` in `libcore` and `libstd`

r? @eddyb
2016-08-25 20:45:32 -07:00
Jeffrey Seyfried
a9a2979dba Remove needless imports in libcollections. 2016-08-24 22:13:13 +00:00
Eduard Burtescu
119508cdb4 Remove drop flags from structs and enums implementing Drop. 2016-08-24 13:23:37 +03:00
Steven Allen
c7d5f7e5e6 Rust has type aliases, not typedefs.
They're the same thing but it's better to keep the terminology consistent.
2016-08-23 10:49:11 -04:00
bors
0bd99f9d5c Auto merge of #35656 - Stebalien:fused, r=alexcrichton
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-23 07:46:52 -07:00
Christopher Serr
18445cd6cc Fix "Furthermore" Typo in String Docs
It used to say "Furtheremore" instead of "Furthermore".
2016-08-21 22:51:37 +02:00
Steven Allen
f2655e23ff Note that formatters should not return spurious errors.
Doing otherwise would break traits like `ToString`.
2016-08-20 18:00:42 -04:00
Steven Allen
e4dd785b59 Correct formatting docs: fmt::Result != io::Result<()> 2016-08-20 15:20:22 -04:00
Jonathan Turner
d5595d1f3e Rollup merge of #35234 - nrc:rustdoc-macros, r=steveklabnik
rustdoc: remove the `!` from macro URLs and titles

Because the `!` is part of a macro use, not the macro's name. E.g., you write `macro_rules! foo` not `macro_rules! foo!`, also `#[macro_import(foo)]`.

(Pulled out of #35020).
2016-08-20 07:09:33 -07:00
Alex Crichton
afeeadeae5 std: Stabilize APIs for the 1.12 release
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-19 11:59:56 -07:00
Steven Allen
de91872a33 Add a FusedIterator trait.
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-18 12:16:29 -04:00
Nick Cameron
e6cc4c5d13 Fix links 2016-08-18 15:43:35 +12:00
bors
7ac11cad3f Auto merge of #35747 - jonathandturner:rollup, r=jonathandturner
Rollup of 23 pull requests

- Successful merges: #34370, #35415, #35595, #35610, #35613, #35614, #35621, #35660, #35663, #35670, #35671, #35672, #35681, #35686, #35690, #35695, #35707, #35708, #35713, #35722, #35725, #35726, #35731
- Failed merges: #35395
2016-08-17 09:49:34 -07:00
bors
76fa5875c6 Auto merge of #35733 - apasel422:issue-35721, r=alexcrichton
Make `vec::IntoIter` covariant again

Closes #35721

r? @alexcrichton
2016-08-17 06:25:56 -07:00
Jonathan Turner
3dd060f065 Rollup merge of #35707 - frewsxcv:vec-into-iter-debug, r=alexcrichton
Implement `Debug` for `std::vec::IntoIter`.

Display all the remaining items of the iterator, similar to the `Debug`
implementation for `core::slice::Iter`:

f0bab98695/src/libcore/slice.rs (L930-L937)

Using the `as_slice` method that was added in:

https://github.com/rust-lang/rust/pull/35447
2016-08-17 06:25:26 -07:00
Andrew Paseltiner
7e148cd062
Make vec::IntoIter covariant again
Closes #35721
2016-08-16 20:45:07 -04:00
bors
514d4cef24 Auto merge of #35354 - tomgarcia:covariant-drain, r=alexcrichton
Made vec_deque::Drain, hash_map::Drain, and hash_set::Drain covariant

Fixed the rest of the Drain iterators.
2016-08-16 13:26:15 -07:00
Corey Farwell
bc52bdcedc Implement Debug for std::vec::IntoIter.
Display all the remaining items of the iterator, similar to the `Debug`
implementation for `core::slice::Iter`:

f0bab98695/src/libcore/slice.rs (L930-L937)

Using the `as_slice` method that was added in:

https://github.com/rust-lang/rust/pull/35447
2016-08-15 23:45:12 -04:00
Eduard-Mihai Burtescu
b975a120e1 Rollup merge of #35598 - tshepang:needless-binding, r=steveklabnik
string: remove needless binding
2016-08-14 20:29:50 +03:00
Eduard-Mihai Burtescu
322aa6e021 Rollup merge of #35597 - tshepang:it-is-a-slice, r=steveklabnik
doc: a value of type `&str` is called a "string slice"
2016-08-14 20:29:50 +03:00
Eduard-Mihai Burtescu
6d8af8cf5d Rollup merge of #35447 - frewsxcv:vec-into-iter-as-slice, r=alexcrichton
Introduce `as_slice`/`as_mut_slice` methods on `std::vec::IntoIter` struct.

Similar to the `as_slice` method on `core::slice::Iter` struct.
2016-08-14 20:29:48 +03:00
Corey Farwell
01a766e521 Introduce as_mut_slice method on std::vec::IntoIter struct. 2016-08-11 16:49:01 -04:00
Corey Farwell
d099e30e48 Introduce as_slice method on std::vec::IntoIter struct.
Similar to the `as_slice` method on `core::slice::Iter` struct.
2016-08-11 16:48:43 -04:00
Tshepang Lekhonkhobe
071410ba57 string: remove needless binding 2016-08-11 20:44:49 +02:00
Tshepang Lekhonkhobe
c99c2ea838 doc: a value of type &str is called a "string slice" 2016-08-11 20:41:31 +02:00
Murarth
0a3564afaf Add tracking issue for String::insert_str 2016-08-09 11:42:16 -07:00
bors
58c5716e2d Auto merge of #34762 - creativcoder:slice-ext, r=alexcrichton
extend lifetime on binary_search_by_key of SliceExt trait

Fixes #34683.
2016-08-08 21:51:01 -07:00
Rahul Sharma
6fd1752b25 extend lifetime on binary_search_by_key of SliceExt trait 2016-08-09 00:32:35 +05:30
Alexander Altman
42e64bc5f2 Add FromIterator implementations for Cow<str>
This seems like an oversight, since the corresponding implementation for `Cow<[T]> where T: Clone` exists.
2016-08-07 13:41:31 -07:00
Guillaume Gomez
3ca18f725a Rollup merge of #35181 - GuillaumeGomez:vec_doc, r=steveklabnik
Add doc example for Vec

Fixes #29380.

r? @steveklabnik
2016-08-05 16:12:54 +02:00
Thomas Garcia
bf592cefde Made vec_deque::Drain, hash_map::Drain, and hash_set::Drain covariant 2016-08-04 21:33:57 -07:00
Guillaume Gomez
1fa9b8dc96 Add doc example for Vec 2016-08-02 20:45:31 +02:00
Corey Farwell
727d9293e4 Add doc examples for range::RangeArgument::{start,end}. 2016-08-02 09:01:46 -04:00
bors
19765f2ab1 Auto merge of #35054 - pwoolcoc:stringfromchars, r=brson
implement `From<Vec<char>>` and `From<&'a [char]>` for `String`

Though there are ways to convert a slice or vec of chars into a string,
it would be nice to be able to just do `String::from(&['a', 'b', 'c'])`,
so this PR implements `From<Vec<char>>` and `From<&'a [char]>` for
String.
2016-08-01 20:05:57 -07:00
Seo Sanghyeon
2effa8982e Rollup merge of #35134 - frewsxcv:slice-chunks, r=GuillaumeGomez
Rewrite `slice::chunks` doc example to not require printing.

None
2016-08-02 00:12:40 +09:00
Vadim Petrochenkov
a80d329b68 Don't gate methods Fn(Mut,Once)::call(mut,once) with feature unboxed_closures
They are already gated with feature `fn_traits`
2016-07-31 17:48:20 +03:00
Corey Farwell
2eea1f3097 Rewrite slice::chunks doc example to not require printing. 2016-07-30 23:21:48 -04:00
Manish Goregaokar
ce79972314 Rollup merge of #35104 - frewsxcv:linked-list-append, r=steveklabnik
Rewrite `collections::LinkedList::append` doc example.

None
2016-07-30 13:44:47 +05:30
Guillaume Gomez
72d1d06692 Rollup merge of #35050 - knight42:improve-fmt-doc, r=steveklabnik
More intuitive explantion of strings formatting
2016-07-29 11:57:53 +02:00
Corey Farwell
f459e801fd Rewrite collections::LinkedList::append doc example. 2016-07-28 22:09:31 -04:00
bors
d1df3fecdf Auto merge of #34485 - tbu-:pr_unicode_debug_str, r=alexcrichton
Escape fewer Unicode codepoints in `Debug` impl of `str`

Use the same procedure as Python to determine whether a character is
printable, described in [PEP 3138]. In particular, this means that the
following character classes are escaped:

- Cc (Other, Control)
- Cf (Other, Format)
- Cs (Other, Surrogate), even though they can't appear in Rust strings
- Co (Other, Private Use)
- Cn (Other, Not Assigned)
- Zl (Separator, Line)
- Zp (Separator, Paragraph)
- Zs (Separator, Space), except for the ASCII space `' '` `0x20`

This allows for user-friendly inspection of strings that are not
English (e.g. compare `"\u{e9}\u{e8}\u{ea}"` to `"éèê"`).

Fixes #34318.
CC #34422.

[PEP 3138]: https://www.python.org/dev/peps/pep-3138/
2016-07-28 11:20:33 -07:00
bors
cec262e55a Auto merge of #34951 - tomgarcia:covariant-vec, r=brson
Make vec::Drain and binary_heap::Drain covariant

I removed all mutable pointers/references, and added covariance tests similar to the ones in #32635. It builds and passes the tests, but I noticed that there weren't any tests of Drain's behaviour (at least not in libcollectionstest), so I'm not sure if my changes accidently broke Drain's behaviour. Should I add some tests for that (and if so, what should the tests include)?
2016-07-28 05:24:31 -07:00
Tobias Bucher
3d09b4a0d5 Rename char::escape to char::escape_debug and add tracking issue 2016-07-28 02:20:49 +02:00
Paul Woolcock
ac73335f2f implement From<Vec<char>> and From<&'a [char]> for String
Though there are ways to convert a slice or vec of chars into a string,
it would be nice to be able to just do `String::from(['a', 'b', 'c'])`,
so this PR implements `From<Vec<char>>` and `From<&'a [char]>` for
String.
2016-07-27 12:07:49 -04:00