about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
AgeCommit message (Collapse)AuthorLines
2019-03-09Use lifetime contravariance to elide more lifetimes in core+alloc+stdScott McMurray-8/+8
2019-03-05Add a tracking issue for new as_slice methodsJosh Stone-1/+1
2019-03-04Add as_slice() to slice::IterMut and vec::DrainJosh Stone-0/+19
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-01Fix typo in Vec#resize_with documentationJens Hausdorf-1/+1
2019-02-23Rollup merge of #58628 - RReverser:optimise-vec-false, r=oli-obkMazdak Farrokhzad-0/+1
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-22Rollup merge of #57656 - scottmcm:deprecate-resize_default, r=SimonSapinMazdak Farrokhzad-0/+4
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-21Optimise vec![false; N] to zero-allocIngvar Stepanyan-0/+1
Nowadays booleans have a well-defined representation, so there is no reason not to optimise their allocation.
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-1/+1
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-17Use more impl header lifetime elisionScott McMurray-1/+1
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-10libs: doc commentsAlexander Regueiro-4/+4
2019-02-10tests: doc commentsAlexander Regueiro-1/+1
2019-02-03liballoc: revert nested imports style changes.Mazdak Farrokhzad-23/+16
2019-02-02liballoc: fix some idiom lints.Mazdak Farrokhzad-7/+7
2019-02-02liballoc: elide some lifetimes.Mazdak Farrokhzad-15/+15
2019-02-02liballoc: prefer imports of borrow from libcore.Mazdak Farrokhzad-2/+1
2019-02-02liballoc: adjust abolute imports + more import fixes.Mazdak Farrokhzad-9/+3
2019-02-02liballoc: refactor & fix some imports.Mazdak Farrokhzad-22/+27
2019-02-02liballoc: cargo check passes on 2018Mazdak Farrokhzad-5/+5
2019-01-15Deprecate the unstable Vec::resize_defaultScott McMurray-0/+4
2019-01-13Add a debug_assert to Vec::set_lenScott McMurray-0/+2
2019-01-12Rollup merge of #56425 - scottmcm:redo-vec-set_len-docs, r=CentrilMazdak Farrokhzad-27/+62
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-09explain safety for vec.set_len(0)Mazdak Farrokhzad-0/+3
2019-01-02Update src/liballoc/vec.rs Mazdak Farrokhzad-0/+4
Add @centril's comment Co-Authored-By: scottmcm <scottmcm@users.noreply.github.com>
2018-12-25Remove licensesMark Rousskov-10/+0
2018-12-19Stabilize Vec(Deque)::resize_withScott McMurray-3/+1
Closes #41758
2018-12-11Update the comment some more following CR feedbackScott McMurray-9/+11
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-1/+1
2018-12-02Update issue number of `shrink_to` methods to point the tracking issueHidehito Yabuuchi-1/+1
2018-12-01Redo the docs for Vec::set_lenScott McMurray-27/+53
Inspired by the recent conversation on IRLO.
2018-10-09Refactor macro comment and add resize with zeros examplemandeep-2/+6
2018-10-05Add doc comments about safest way to initialize a vector of zerosmandeep-1/+3
2018-10-02Make spec_extend use for_each()Nathan West-2/+2
2018-09-23Make the `Vec::dedup` method use `slice::partition_dedup` internallyClément Renault-84/+6
2018-09-23Introduce the partition_dedup/by/by_key methods for slicesClément Renault-5/+5
2018-09-16use mem::zeroed to make up ZST valuesRalf Jung-4/+4
2018-08-29fix some uses of pointer intrinsics with invalid pointersRalf Jung-6/+4
2018-08-20Replace usages of ptr::offset with ptr::{add,sub}.Corey Farwell-16/+16
2018-07-31Use SetLenOnDrop in Vec::truncate()Laurentiu Nicola-6/+17
This avoids a redundant length check in some cases when calling `Vec::truncate` or `Vec::clear`. Fixes #51802
2018-07-09Removed a single trailing space. Oops.Orson Peters-1/+1
2018-07-09Reimplemented Vec's swap_remove to not rely on pop.Orson Peters-4/+6
2018-07-09Performance improvement of Vec's swap_remove.Orson Peters-3/+7
2018-06-29Move core::alloc::CollectionAllocErr to alloc::collectionsSimon Sapin-1/+1
2018-06-19Add message to `rustc_on_unimplemented` attributes in coreEsteban Küber-2/+8
2018-05-24stabilize RangeBounds collections_range #30877Cory Sherman-2/+2
rename RangeBounds::start() -> start_bound() rename RangeBounds::end() -> end_bound()
2018-05-21Auto merge of #50739 - gnzlbg:vec_reserve, r=sfacklerbors-2/+2
Switch Vec from doubling size on growth to using RawVec's reserve On growth, Vec does not require to exactly double its size for correctness, like, for example, VecDeque does. Using reserve instead better expresses this intent. It also allows to reuse Excess capacity on growth and for better growth-policies to be provided by RawVec. r? @sfackler
2018-05-17Switch to 1.26 bootstrap compilerMark Simulacrum-3/+0
2018-05-17Rollup merge of #50170 - burtonageo:more_cow_from, r=alexcrichtonkennytm-0/+7
Implement From for more types on Cow This is basically https://github.com/rust-lang/rust/pull/48191, except that it should be implemented in a way that doesn't break third party crates.
2018-05-14Switch Vec from doubling size on growth to using RawVec's reservegnzlbg-2/+2
On growth, Vec does not require to exactly double its size for correctness, like, for example, VecDeque does. Using reserve instead better expresses this intent. It also allows to reuse Excess capacity on growth and for better growth-policies to be provided by RawVec.
2018-05-09std: Avoid `ptr::copy` if unnecessary in `vec::Drain`Alex Crichton-3/+5
This commit is spawned out of a performance regression investigation in #50496. In tracking down this regression it turned out that the `expand_statements` function in the compiler was taking quite a long time. Further investigation showed two key properties: * The function was "fast" on glibc 2.24 and slow on glibc 2.23 * The hottest function was memmove from glibc Combined together it looked like glibc gained an optimization to the memmove function in 2.24. Ideally we don't want to rely on this optimization, so I wanted to dig further to see what was happening. The hottest part of `expand_statements` was `Drop for Drain` in the call to `splice` where we insert new statements into the original vector. This *should* be a cheap operation because we're draining and replacing iterators of the exact same length, but under the hood memmove was being called a lot, causing a slowdown on glibc 2.23. It turns out that at least one of the optimizations in glibc 2.24 was that `memmove` where the src/dst are equal becomes much faster. [This program][prog] executes in ~2.5s against glibc 2.23 and ~0.3s against glibc 2.24, exhibiting how glibc 2.24 is optimizing `memmove` if the src/dst are equal. And all that brings us to what this commit itself is doing. The change here is purely to `Drop for Drain` to avoid the call to `ptr::copy` if the region being copied doesn't actually need to be copied. For normal usage of just `Drain` itself this check isn't really necessary, but because `Splice` internally contains `Drain` this provides a nice speed boost on glibc 2.23. Overall this should fix the regression seen in #50496 on glibc 2.23 and also fix the regression on Windows where `memmove` looks to not have this optimization. Note that the way `splice` was called in `expand_statements` would cause a quadratic number of elements to be copied via `memmove` which is likely why the tuple-stress benchmark showed such a severe regression. Closes #50496 [prog]: https://gist.github.com/alexcrichton/c05bc51c6771bba5ae5b57561a6c1cd3
2018-05-09Update features to 1.28.0George Burton-1/+1