about summary refs log tree commit diff
path: root/src/libcollections/vec.rs
AgeCommit message (Collapse)AuthorLines
2017-01-14have RangeArgument return a Bound<&T> from each of its methodsdjzin-2/+11
2017-01-10Rollup merge of #38874 - derekdreery:patch-1, r=steveklabnikSeo Sanghyeon-1/+2
Update vec.rs Add a warning not to convert char* from c to Vec<u8> (I thought you could until I asked on irc). Reasoning is that it will help people avoid an error that could cause crashes and undefined behaviour. Only drawback is that it could confuse someone not familiar with C, but beginners are unlikely to be using this function anyway.
2017-01-10Rollup merge of #38664 - apasel422:may-dangle, r=pnkfelixSeo Sanghyeon-4/+2
Replace uses of `#[unsafe_destructor_blind_to_params]` with `#[may_dangle]` CC #34761 r? @pnkfelix
2017-01-06Update vec.rsderekdreery-1/+1
Changed language to stress char is the C meaning (u8) not unicode.
2017-01-06Update vec.rsderekdreery-1/+2
Add a warning not to convert char* from c to Vec<u8> (I thought you could until I asked on irc)
2016-12-28Replace uses of `#[unsafe_destructor_blind_to_params]` with `#[may_dangle]`Andrew Paseltiner-4/+2
CC #34761
2016-12-23Implement placement-in protocol for `Vec`Andrew Paseltiner-1/+73
2016-12-15Stabilize std::vec::IntoIter::{as_slice, as_mut_slice}Aaron Turon-4/+2
2016-12-06vec: More specialization for Extend<&T> for vecUlrik Sverdrup-6/+33
Specialize to use copy_from_slice when extending a Vec with &[T] where T: Copy.
2016-11-23core, collections: Implement better .is_empty() for slice and vec iteratorsUlrik Sverdrup-2/+10
These iterators can use a pointer comparison instead of computing the length.
2016-11-13vec: Use less code bloat specialized Vec::from_iterUlrik Sverdrup-20/+31
Vec::from_iter's general case allocates the vector up front; this is redundant for the TrustedLen case, and can then be avoided to reduce the size of the code.
2016-11-13Restore Vec::from_iter() specializationUlrik Sverdrup-1/+1
Since I said "no intentional functional change" in the previous commit, I guess it was inevitable there were unintentional changes. Not functional, but optimization-wise. This restores the extend specialization's use in Vec::from_iter.
2016-11-11vec: Write the .extend() specialization in cleaner styleUlrik Sverdrup-30/+41
As far as possible, use regular `default fn` specialization in favour of ad-hoc conditionals.
2016-11-04Auto merge of #37306 - bluss:trusted-len, r=alexcrichtonbors-57/+43
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-04Link the tracking issue for TrustedLenUlrik Sverdrup-1/+1
2016-10-31Changed most vec! invocations to use square bracesiirelu-3/+3
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-27vec: Remove the Vec specialization for .extend()Ulrik Sverdrup-13/+0
This now produces as good code (with optimizations) using the TrustedLen codepath.
2016-10-27impl TrustedLen for vec::IntoIterUlrik Sverdrup-0/+3
2016-10-26Vec docs: fix broken links and make quoting consistentDuncan-22/+22
2016-10-22Auto merge of #37326 - SimonSapin:from-cow, r=alexcrichtonbors-0/+7
Implement `From<Cow<str>> for String` and `From<Cow<[T]>> for Vec<T>`. Motivation: the `selectors` crate is generic over a string type, in order to support all of `String`, `string_cache::Atom`, and `gecko_string_cache::Atom`. Multiple trait bounds are used for the various operations done with these strings. One of these operations is creating a string (as efficiently as possible, re-using an existing memory allocation if possible) from `Cow<str>`. The `std::convert::From` trait seems natural for this, but the relevant implementation was missing before this PR. To work around this I’ve added a `FromCowStr` trait in `selectors`, but with trait coherence that means one of `selectors` or `string_cache` needs to depend on the other to implement this trait. Using a trait from `std` would solve this. The `Vec<T>` implementation is just added for consistency. I also tried a more general `impl<'a, O, B: ?Sized + ToOwned<Owned=O>> From<Cow<'a, B>> for O`, but (the compiler thinks?) it conflicts with `From<T> for T` the impl (after moving all of `collections::borrow` into `core::borrow` to work around trait coherence).
2016-10-22Rollup merge of #37043 - GuillaumeGomez:vec_urls, r=frewsxcvGuillaume Gomez-52/+85
Add missing urls on Vec docs r? @steveklabnik
2016-10-21vec: Add a debug assertion where TrustedLen is usedUlrik Sverdrup-1/+7
2016-10-21Implement `From<Cow<str>> for String` and `From<Cow<[T]>> for Vec<T>`.Simon Sapin-0/+7
Motivation: the `selectors` crate is generic over a string type, in order to support all of `String`, `string_cache::Atom`, and `gecko_string_cache::Atom`. Multiple trait bounds are used for the various operations done with these strings. One of these operations is creating a string (as efficiently as possible, re-using an existing memory allocation if possible) from `Cow<str>`. The `std::convert::From` trait seems natural for this, but the relevant implementation was missing before this PR. To work around this I’ve added a `FromCowStr` trait in `selectors`, but with trait coherence that means one of `selectors` or `string_cache` needs to depend on the other to implement this trait. Using a trait from `std` would solve this. The `Vec<T>` implementation is just added for consistency. I also tried a more general `impl<'a, O, B: ?Sized + ToOwned<Owned=O>> From<Cow<'a, B>> for O`, but (the compiler thinks?) it conflicts with `From<T> for T` the impl (after moving all of `collections::borrow` into `core::borrow` to work around trait coherence).
2016-10-21vec: Use Vec::extend specializations in extend_from_slice and moreUlrik Sverdrup-38/+2
The new Vec::extend covers the duties of .extend_from_slice() and some previous specializations.
2016-10-20Use TrustedLen for Vec's FromIterator and ExtendUlrik Sverdrup-10/+36
2016-10-20Add missing urls on Vec docsGuillaume Gomez-52/+85
2016-10-16Update comment in Vec::dedup_byFlorian Diebold-1/+1
2016-10-15Auto merge of #37094 - fhartwig:spec-extend-from-slice, r=alexcrichtonbors-1/+18
Specialize Vec::extend to Vec::extend_from_slice I tried using the existing `SpecExtend` as a helper trait for this, but the instances would always conflict with the instances higher up in the file, so I created a new helper trait. Benchmarking `extend` vs `extend_from_slice` with an slice of 1000 `u64`s gives the following results: ``` before: running 2 tests test tests::bench_extend_from_slice ... bench: 166 ns/iter (+/- 78) test tests::bench_extend_trait ... bench: 1,187 ns/iter (+/- 697) after: running 2 tests test tests::bench_extend_from_slice ... bench: 149 ns/iter (+/- 87) test tests::bench_extend_trait ... bench: 138 ns/iter (+/- 70) ```
2016-10-13Auto merge of #36743 - SimonSapin:dedup-by, r=alexcrichtonbors-83/+126
Add Vec::dedup_by and Vec::dedup_by_key
2016-10-11Specialize Vec::extend to Vec::extend_from_sliceFlorian Hartwig-1/+18
2016-10-11Merge two `impl<T> Vec<T>` blocks.Simon Sapin-126/+124
The show up separately in rustdoc. This is a separate commit to keep the previous one’s diff shorter.
2016-10-11Add Vec::dedup_by and Vec::dedup_by_keySimon Sapin-1/+46
2016-10-01std: Correct stability attributes for some implementationsOliver Middleton-5/+5
These are displayed by rustdoc so should be correct.
2016-09-30Rollup merge of #36623 - GuillaumeGomez:doc_typos, r=steveklabnikSteve Klabnik-2/+2
Fix some typos and improve doc comments style r? @steveklabnik
2016-09-28Remove stage0 hacksBrian Anderson-1/+0
2016-09-24Fix some typos and improve doc comments styleGuillaume Gomez-2/+2
2016-09-14Rollup merge of #36396 - athulappadan:Default-docs, r=blussGuillaume Gomez-0/+1
Documentation of what Default does for each type Addresses #36265 I haven't changed the following types due to doubts: 1)src/libstd/ffi/c_str.rs 2)src/libcore/iter/sources.rs 3)src/libcore/hash/mod.rs 4)src/libcore/hash/mod.rs 5)src/librustc/middle/privacy.rs r? @steveklabnik
2016-09-11Documentation of what does for each typeathulappadan-0/+1
2016-09-09Work around pointer aliasing issue in Vec::extend_from_slice, ↵Ulrik Sverdrup-13/+55
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-08-24Remove drop flags from structs and enums implementing Drop.Eduard Burtescu-6/+4
2016-08-18Add a FusedIterator trait.Steven Allen-1/+7
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-17Auto merge of #35747 - jonathandturner:rollup, r=jonathandturnerbors-0/+9
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-16Make `vec::IntoIter` covariant againAndrew Paseltiner-6/+9
Closes #35721
2016-08-15Implement `Debug` for `std::vec::IntoIter`.Corey Farwell-0/+9
Display all the remaining items of the iterator, similar to the `Debug` implementation for `core::slice::Iter`: https://github.com/rust-lang/rust/blob/f0bab98695f0a4877daabad9a5b0ba3e66121392/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-11Introduce `as_mut_slice` method on `std::vec::IntoIter` struct.Corey Farwell-9/+29
2016-08-11Introduce `as_slice` method on `std::vec::IntoIter` struct.Corey Farwell-3/+22
Similar to the `as_slice` method on `core::slice::Iter` struct.
2016-08-02Add doc example for VecGuillaume Gomez-0/+19
2016-07-28Auto merge of #34951 - tomgarcia:covariant-vec, r=brsonbors-5/+6
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-23Fix incorrect 'memory leak' example for `Vec::set_len`.Corey Farwell-3/+4
Example was written in https://github.com/rust-lang/rust/pull/34911 Issue was brought up in this comment: https://github.com/rust-lang/rust/commit/a005b2cd2ac679da7393e537aa05e2b7d32d36d5#commitcomment-18346958
2016-07-21Readding lifetime parameters and removing allocationThomas Garcia-23/+44