summary refs log tree commit diff
path: root/src/libcollections/vec.rs
AgeCommit message (Collapse)AuthorLines
2017-03-17Stabilize rc_raw feature, closes #37197Aaron Turon-2/+2
2017-03-07Added remove_from to vec.rsmadseagames-0/+21
2017-02-26Auto merge of #39738 - keeperofdakeys:vec-docs, r=GuillaumeGomezbors-0/+6
Add notes about capacity effects to Vec::truncate() Add notes about the effects of Vec::truncate() and Vec::clear() on the capacity of a vector.
2017-02-16Additional docs for Vec, String, and slice trait implsMatt Brubeck-0/+2
2017-02-14Add notes about capacity effects to Vec::truncate()Josh-0/+6
2017-02-13typo fixking6cong-1/+1
2017-02-09Explicitly mention that `Vec::reserve` is based on len not capacitySean Griffin-3/+6
I spent a good chunk of time tracking down a buffer overrun bug that resulted from me mistakenly thinking that `reserve` was based on the current capacity not the current length. It would be helpful if this were called out explicitly in the docs.
2017-02-07Auto merge of #39002 - GuillaumeGomez:debug_libcollections, r=aturonbors-0/+10
Add Debug implementations for libcollection structs Part of #31869.
2017-02-05Replace PlaceBack Debug implementation with deriveGuillaume Gomez-11/+3
2017-02-02std: Fix IntoIter::as_mut_slice's signatureAlex Crichton-1/+1
This was intended to require `&mut self`, not `&self`, otherwise it's unsound! Closes #39465
2017-01-25std: Stabilize APIs for the 1.16.0 releaseAlex Crichton-5/+2
This commit applies the stabilization/deprecations of the 1.16.0 release, as tracked by the rust-lang/rust issue tracker and the final-comment-period tag. The following APIs were stabilized: * `VecDeque::truncate` * `VecDeque::resize` * `String::insert_str` * `Duration::checked_{add,sub,div,mul}` * `str::replacen` * `SocketAddr::is_ipv{4,6}` * `IpAddr::is_ipv{4,6}` * `str::repeat` * `Vec::dedup_by` * `Vec::dedup_by_key` * `Result::unwrap_or_default` * `<*const T>::wrapping_offset` * `<*mut T>::wrapping_offset` * `CommandExt::creation_flags` (on Windows) * `File::set_permissions` * `String::split_off` The following APIs were deprecated * `EnumSet` - replaced with other ecosystem abstractions, long since unstable Closes #27788 Closes #35553 Closes #35774 Closes #36436 Closes #36949 Closes #37079 Closes #37087 Closes #37516 Closes #37827 Closes #37916 Closes #37966 Closes #38080
2017-01-20Remove Debug implementations specializationGuillaume Gomez-14/+0
2017-01-20Add Debug implementations for libcollection structsGuillaume Gomez-0/+32
2017-01-17Clarify when range is removed by drainStephen E. Baker-2/+2
Based on a discussion on #rust-beginners the existing note for drain is confusing. This new wording was suggested.
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