Commit Graph

118 Commits

Author SHA1 Message Date
Mark Rousskov a06baa56b9 Format the world 2019-12-22 17:42:47 -05:00
Mark Rousskov 82184440ec Propagate cfg bootstrap 2019-12-18 12:16:19 -05:00
Oliver Scherer 5e17e39881 Require stable/unstable annotations for the constness of all stable functions with a const modifier 2019-12-13 11:27:02 +01:00
Yuki Okushi b94a2f9e38 Rollup merge of #66111 - RalfJung:from_raw_parts, r=Centril
improve from_raw_parts docs

Triggered by https://github.com/rust-lang/rfcs/pull/2806. Hopefully this helps clarify that joining slices across allocations is not possible in Rust currently.

r? @Centril
2019-11-07 09:20:41 +09:00
Ralf Jung 6a1f303b98 also edit String::from_raw_parts while we are at it 2019-11-05 09:57:52 +01:00
Jeff Dickey d9ec5fa88c doc(str): show example of chars().count() under len()
the docs are great at explaining that .len() isn't like in other
languages but stops short of explaining how to get the character length.

r? @steveklabnik
2019-11-01 20:18:33 -07:00
Jake Goulding 6600cf6040 Add {String,Vec}::into_raw_parts 2019-10-25 11:25:52 -04:00
Jake Goulding dce8fabc62 Use ManuallyDrop in examples for {Vec,String}::from_raw_parts 2019-10-25 11:22:53 -04:00
Jake Goulding 0d21d257c9 Remove unneeded pointer casting 2019-10-25 11:20:47 -04:00
Lzu Tao 6c1b447f2e Remove unneeded fn main blocks from docs 2019-10-01 11:55:46 +00:00
Mark Rousskov f359a94849 Snap cfgs to new beta 2019-09-25 08:42:46 -04:00
jordins 62dc7948d1 fix several issues in String docs
- In some places &str was shown instead of String.
- into_bytes is the reverse of from_utf8

Fixes #63797
2019-09-24 15:25:24 +02:00
Mazdak Farrokhzad 9b3e11f635 Const-stabilize String::new. 2019-09-16 16:45:16 +02:00
Simon Sapin 36b18a1901 Rename CollectionAllocError to TryReserveError 2019-08-16 18:08:06 +02:00
Vadim Petrochenkov 676d282dd3 Deny unused_lifetimes through rustbuild 2019-07-28 18:47:02 +03:00
Mazdak Farrokhzad 0f92eb8a4a Rollup merge of #62123 - jeremystucki:needless_lifetimes_std, r=alexcrichton
Remove needless lifetimes (std)

Split from #62039
2019-07-05 13:52:58 +02:00
Kyle Huey db16e17212 When possible without changing semantics, implement Iterator::last in terms of DoubleEndedIterator::next_back for types in liballoc and libcore.
Provided that the iterator has finite length and does not trigger user-provided code, this is safe.

What follows is a full list of the DoubleEndedIterators in liballoc/libcore and whether this optimization is safe, and if not, why not.

src/liballoc/boxed.rs
Box: Pass through to avoid defeating optimization of the underlying DoubleIterator implementation. This has no correctness impact.

src/liballoc/collections/binary_heap.rs
Iter: Pass through to avoid defeating optimizations on slice::Iter
IntoIter: Not safe, changes Drop order
Drain: Not safe, changes Drop order

src/liballoc/collections/btree/map.rs
Iter: Safe to call next_back, invokes no user defined code.
IterMut: ditto
IntoIter: Not safe, changes Drop order
Keys: Safe to call next_back, invokes no user defined code.
Values: ditto
ValuesMut: ditto
Range: ditto
RangeMut: ditto

src/liballoc/collections/btree/set.rs
Iter: Safe to call next_back, invokes no user defined code.
IntoIter: Not safe, changes Drop order
Range: Safe to call next_back, invokes no user defined code.

src/liballoc/collections/linked_list.rs
Iter: Safe to call next_back, invokes no user defined code.
IterMut: ditto
IntoIter: Not safe, changes Drop order

src/liballoc/collections/vec_deque.rs
Iter: Safe to call next_back, invokes no user defined code.
IterMut: ditto
IntoIter: Not safe, changes Drop order
Drain: ditto

src/liballoc/string.rs
Drain: Safe because return type is a primitive (char)

src/liballoc/vec.rs
IntoIter: Not safe, changes Drop order
Drain: ditto
Splice: ditto

src/libcore/ascii.rs
EscapeDefault: Safe because return type is a primitive (u8)

src/libcore/iter/adapters/chain.rs
Chain: Not safe, invokes user defined code (Iterator impl)

src/libcore/iter/adapters/flatten.rs
FlatMap: Not safe, invokes user defined code (Iterator impl)
Flatten: ditto
FlattenCompat: ditto

src/libcore/iter/adapters/mod.rs
Rev: Not safe, invokes user defined code (Iterator impl)
Copied: ditto
Cloned: Not safe, invokes user defined code (Iterator impl and T::clone)
Map: Not safe, invokes user defined code (Iterator impl + closure)
Filter: ditto
FilterMap: ditto
Enumerate: Not safe, invokes user defined code (Iterator impl)
Skip: ditto
Fuse: ditto
Inspect: ditto

src/libcore/iter/adapters/zip.rs
Zip: Not safe, invokes user defined code (Iterator impl)

src/libcore/iter/range.rs
ops::Range: Not safe, changes Drop order, but ALREADY HAS SPECIALIZATION
ops::RangeInclusive: ditto

src/libcore/iter/sources.rs
Repeat: Not safe, calling last should iloop.
Empty: No point, iterator is at most one item long.
Once: ditto
OnceWith: ditto

src/libcore/option.rs
Item: No point, iterator is at most one item long.
Iter: ditto
IterMut: ditto
IntoIter: ditto

src/libcore/result.rs
Iter: No point, iterator is at most one item long
IterMut: ditto
IntoIter: ditto

src/libcore/slice/mod.rs
Split: Not safe, invokes user defined closure
SplitMut: ditto
RSplit: ditto
RSplitMut: ditto
Windows: Safe, already has specialization
Chunks: ditto
ChunksMut: ditto
ChunksExact: ditto
ChunksExactMut: ditto
RChunks: ditto
RChunksMut: ditto
RChunksExact: ditto
RChunksExactMut: ditto

src/libcore/str/mod.rs
Chars: Safe, already has specialization
CharIndices: ditto
Bytes: ditto
Lines: Safe to call next_back, invokes no user defined code.
LinesAny: Deprecated
Everything that is generic over P: Pattern: Not safe because Pattern invokes user defined code.
SplitWhitespace: Safe to call next_back, invokes no user defined code.
SplitAsciiWhitespace: ditto
2019-07-02 13:45:29 -07:00
Jeremy Stucki 47ea8ae022 Remove needless lifetimes 2019-07-01 12:15:27 +02:00
Steven Fackler 8a22bc3b30 Revert "Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators."
This reverts commit 3e86cf36b5.
2019-05-22 14:09:34 -07:00
Mazdak Farrokhzad f08c5bbc85 Rollup merge of #59825 - jsgf:from-ref-string, r=sfackler
string: implement From<&String> for String

Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing `&String` to an `impl Into<String>`
parameter frictionless.

Fixes #59827.
2019-05-16 10:43:24 +02:00
Mazdak Farrokhzad bab03cecfe Rollup merge of #60130 - khuey:efficient_last, r=sfackler
Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators

Provided a `DoubleEndedIterator` has finite length, `Iterator::last` is equivalent to `DoubleEndedIterator::next_back`. But searching forwards through the iterator when it's unnecessary is obviously not good for performance. I ran into this on one of the collection iterators.

I tried adding appropriate overloads for a bunch of the iterator adapters like filter, map, etc, but I ran into a lot of type inference failures after doing so.

The other interesting case is what to do with `Repeat`. Do we consider it part of the contract that `Iterator::last` will loop forever on it? The docs do say that the iterator will be evaluated until it returns None. This is also relevant for the adapters, it's trivially easy to observe whether a `Map` adapter invoked its closure a zillion times or just once for the last element.
2019-05-14 22:00:09 +02:00
Josh Stone 0545375ca6 Add examples of ordered retain 2019-05-10 18:01:50 -07:00
Josh Stone 9b3583375d Document the order of {Vec,VecDeque,String}::retain
It's natural for `retain` to work in order from beginning to end, but
this wasn't actually documented to be the case. If we actually promise
this, then the caller can do useful things like track the index of each
element being tested, as [discussed in the forum][1]. This is now
documented for `Vec`, `VecDeque`, and `String`.

[1]: https://users.rust-lang.org/t/vec-retain-by-index/27697

`HashMap` and `HashSet` also have `retain`, and the `hashbrown`
implementation does happen to use a plain `iter()` order too, but it's
not certain that this should always be the case for these types.
2019-04-29 18:32:05 -07:00
Kyle Huey 3e86cf36b5 Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators.
r?Manishearth
2019-04-19 21:52:43 -07:00
Jeremy Fitzhardinge 08b0aca05e string: implement From<&String> for String
Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing &String to an `impl Into<String>`
parameter frictionless.
2019-04-09 16:52:05 -07:00
Scott McMurray df4ea90b39 Use lifetime contravariance to elide more lifetimes in core+alloc+std 2019-03-09 19:10:28 -08:00
Simon Sapin 85f13f0d42 Add a convert::Infallible empty enum, make string::ParseError an alias 2019-02-13 18:00:18 +01:00
Alexander Regueiro 99ed06eb88 libs: doc comments 2019-02-10 23:57:25 +00:00
Mazdak Farrokhzad 2396780cda liballoc: revert nested imports style changes. 2019-02-03 08:27:44 +01:00
Mazdak Farrokhzad 857530cef1 liballoc: fix some idiom lints. 2019-02-02 12:48:12 +01:00
Mazdak Farrokhzad e70c2fbd5c liballoc: elide some lifetimes. 2019-02-02 12:23:15 +01:00
Mazdak Farrokhzad 3bfa0a35f6 liballoc: prefer imports of borrow from libcore. 2019-02-02 10:53:27 +01:00
Mazdak Farrokhzad f09f62f62c liballoc: adjust abolute imports + more import fixes. 2019-02-02 10:34:36 +01:00
Mazdak Farrokhzad 7693e3e666 liballoc: refactor & fix some imports. 2019-02-02 10:14:40 +01:00
Mazdak Farrokhzad e6e27924e1 liballoc: cargo check passes on 2018 2019-02-02 08:36:45 +01:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
BeatButton 6f288ea337 Fix typo 2018-12-09 14:10:20 -07:00
Pietro Albini e9e92d53ad Rollup merge of #56548 - Lucretiel:string-extend-optimize, r=sfackler
Optimized string FromIterator + Extend impls

I noticed that there was a lost opportunity to reuse string buffers in `FromIterator<String>` and `FromIterator<Cow<str>>`; updated the implementations to use these. In practice this translates to at least one fewer allocation when using these APIs.

Additionally, rewrote `Extend` implementations to use `iter.for_each`, which (supposedly) helps the compiler optimize those loops (because iterator adapters are encouraged to provide optimized implementations of `fold` and `try_fold`.
2018-12-06 07:49:01 +01:00
Nathan West 811a2bfe53 Added explainatory comments 2018-12-05 17:46:03 -08:00
Nathan West 823dd8ca33 Fixed mutability 2018-12-05 15:11:32 -08:00
Nathan West 180dcc3118 Optimized string FromIterator impls 2018-12-05 14:51:04 -08:00
ljedrz d0c64bb296 cleanup: remove static lifetimes from consts 2018-12-04 12:46:10 +01:00
Hidehito Yabuuchi 1e18cc916f Update issue number of shrink_to methods to point the tracking issue 2018-12-02 16:08:08 +09:00
ljedrz 591607d237 String: add a FIXME to from_utf16 2018-11-21 10:17:54 +01:00
Pietro Albini 3b40434940 Rollup merge of #55530 - ljedrz:speed_up_String_from_utf16, r=SimonSapin
Speed up String::from_utf16

Collecting into a `Result` is idiomatic, but not necessarily fast due to rustc not being able to preallocate for the resulting collection. This is fine in case of an error, but IMO we should optimize for the common case, i.e. a successful conversion.

This changes the behavior of `String::from_utf16` from collecting into a `Result` to pushing to a preallocated `String` in a loop.

According to [my simple benchmark](https://gist.github.com/ljedrz/953a3fb74058806519bd4d640d6f65ae) this change makes `String::from_utf16` around **twice** as fast.
2018-11-15 11:04:31 +01:00
Denis Vasilik 6f3add34ca Minor style guide corrections. 2018-11-11 20:11:25 +01:00
Denis Vasilik dc0fd65af2 Whitespace cleanup according to Rust's style guidelines. 2018-11-11 16:58:00 +01:00
Denis Vasilik f0bfbd3e72 Added comments for trait implementations. 2018-11-11 15:44:15 +01:00
Denis Vasilik 93b5112c16 Added comment for From trait implementation: boxed string slice to String 2018-11-11 15:43:43 +01:00
kennytm 9d9146ad95 Rollup merge of #55734 - teresy:shorthand-fields, r=davidtwco
refactor: use shorthand fields

refactor: use shorthand for single fields everywhere (excluding tests).
2018-11-07 21:27:00 +08:00