Ralf Jung
428ab7e1bd
shadow as_ptr as as_mut_ptr in Vec to avoid going through Deref
2019-05-25 10:36:07 +02:00
Ralf Jung
f44b264447
fix dangling reference in Vec::append
2019-05-23 16:30:54 +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
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
Scott McMurray
df4ea90b39
Use lifetime contravariance to elide more lifetimes in core+alloc+std
2019-03-09 19:10:28 -08:00
Josh Stone
e478cadbbe
Add a tracking issue for new as_slice methods
2019-03-05 16:28:32 -08:00
Josh Stone
538a0963ff
Add as_slice() to slice::IterMut and vec::Drain
...
In bluss/indexmap#88 , we found that there was no easy way to implement
`Debug` for our `IterMut` and `Drain` iterators. Those are built on
`slice::IterMut` and `vec::Drain`, which implement `Debug` themselves,
but have no other way to access their data. With a new `as_slice()`
method, we can read the data and customize its presentation.
2019-03-04 15:12:45 -08:00
Jens Hausdorf
670a4d65d5
Fix typo in Vec#resize_with documentation
2019-03-01 13:19:00 +01:00
Mazdak Farrokhzad
93bfa92a3d
Rollup merge of #58628 - RReverser:optimise-vec-false, r=oli-obk
...
Optimise vec![false; N] to zero-alloc
Nowadays booleans have a well-defined representation, so there is no reason not to optimise their allocation.
2019-02-23 09:25:32 +01:00
Mazdak Farrokhzad
0bcb66469c
Rollup merge of #57656 - scottmcm:deprecate-resize_default, r=SimonSapin
...
Deprecate the unstable Vec::resize_default
As a way to either get additional feedback to stabilize or help move nightly users off it.
Tracking issue: https://github.com/rust-lang/rust/issues/41758#issuecomment-449719961
r? @SimonSapin
2019-02-22 14:57:55 +01:00
Ingvar Stepanyan
9f58c5fa7c
Optimise vec![false; N] to zero-alloc
...
Nowadays booleans have a well-defined representation, so there is no reason not to optimise their allocation.
2019-02-21 23:02:34 +00:00
kennytm
e3a8f7db47
Rollup merge of #58553 - scottmcm:more-ihle, r=Centril
...
Use more impl header lifetime elision
Inspired by seeing explicit lifetimes on these two:
- https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator
- https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not
And a follow-up to https://github.com/rust-lang/rust/pull/54687 , that started using IHLE in libcore.
Most of the changes in here fall into two big categories:
- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)
I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm ).
I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-20 11:59:10 +08:00
Scott McMurray
3bea2ca49d
Use more impl header lifetime elision
...
There are two big categories of changes in here
- Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`)
- Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`)
I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-17 19:42:36 -08:00
Alexander Regueiro
99ed06eb88
libs: doc comments
2019-02-10 23:57:25 +00:00
Alexander Regueiro
b87363e763
tests: doc comments
2019-02-10 23:42:32 +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
Scott McMurray
81cd1e64f3
Deprecate the unstable Vec::resize_default
2019-01-15 20:51:44 -08:00
Scott McMurray
1fd971c3b9
Add a debug_assert to Vec::set_len
2019-01-13 22:40:25 -08:00
Mazdak Farrokhzad
e69a5cb2d7
Rollup merge of #56425 - scottmcm:redo-vec-set_len-docs, r=Centril
...
Redo the docs for Vec::set_len
Inspired by the [recent conversation on IRLO](https://internals.rust-lang.org/t/make-vec-set-len-enforce-the-len-cap-invariant/8927/23?u=scottmcm ).
This is just my first stab at this; suggestions welcome.
2019-01-12 10:54:51 +01:00
Mazdak Farrokhzad
5052197e44
explain safety for vec.set_len(0)
2019-01-09 04:17:24 +01:00
Mazdak Farrokhzad
61fb909559
Update src/liballoc/vec.rs
...
Add @centril's comment
Co-Authored-By: scottmcm <scottmcm@users.noreply.github.com>
2019-01-02 21:05:37 -08:00
Mark Rousskov
2a663555dd
Remove licenses
2018-12-25 21:08:33 -07:00
Scott McMurray
7b6cf6e87b
Stabilize Vec(Deque)::resize_with
...
Closes #41758
2018-12-19 22:00:25 -08:00
Scott McMurray
ac642aba07
Update the comment some more following CR feedback
2018-12-11 22:17:35 -08:00
Alexander Regueiro
ee89c088b0
Various minor/cosmetic improvements to code
2018-12-07 23:53:34 +00:00
Hidehito Yabuuchi
1e18cc916f
Update issue number of shrink_to
methods to point the tracking issue
2018-12-02 16:08:08 +09:00
Scott McMurray
5c11392b14
Redo the docs for Vec::set_len
...
Inspired by the recent conversation on IRLO.
2018-12-01 16:35:05 -08:00
mandeep
1e584bf5c9
Refactor macro comment and add resize with zeros example
2018-10-09 01:51:22 -04:00
mandeep
82444aa753
Add doc comments about safest way to initialize a vector of zeros
2018-10-05 18:22:19 -04:00
Nathan West
ec59188025
Make spec_extend use for_each()
2018-10-02 12:35:25 -07:00
Clément Renault
d560292a87
Make the Vec::dedup
method use slice::partition_dedup
internally
2018-09-23 09:10:18 +02:00
Clément Renault
78bccb3540
Introduce the partition_dedup/by/by_key methods for slices
2018-09-23 09:09:54 +02:00
Ralf Jung
357c5dacee
use mem::zeroed to make up ZST values
2018-09-16 14:26:27 +02:00
Ralf Jung
61f0a2b3fd
fix some uses of pointer intrinsics with invalid pointers
2018-08-29 23:08:47 +02:00
Corey Farwell
993fb93464
Replace usages of ptr::offset with ptr::{add,sub}.
2018-08-20 07:28:34 -04:00
Laurentiu Nicola
38e311e448
Use SetLenOnDrop in Vec::truncate()
...
This avoids a redundant length check in some cases when calling
`Vec::truncate` or `Vec::clear`.
Fixes #51802
2018-07-31 20:53:53 +03:00
Orson Peters
e529dfd590
Removed a single trailing space. Oops.
2018-07-09 06:31:24 +02:00
Orson Peters
6faa295cec
Reimplemented Vec's swap_remove to not rely on pop.
2018-07-09 06:13:58 +02:00
Orson Peters
295768ae8f
Performance improvement of Vec's swap_remove.
2018-07-09 05:01:39 +02:00
Simon Sapin
b0547cea0a
Move core::alloc::CollectionAllocErr to alloc::collections
2018-06-29 14:01:33 +02:00
Esteban Küber
776544f011
Add message to rustc_on_unimplemented
attributes in core
2018-06-19 15:19:13 -07:00