about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
AgeCommit message (Collapse)AuthorLines
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
2018-04-29use const trickMark Mansi-1/+1
2018-04-27Update the stable attributes to use the current nightly version numberGeorge Burton-1/+1
2018-04-26not insta-stableMark Mansi-0/+1
2018-04-26make Vec::new const :PMark Mansi-1/+1
2018-04-25Make Vec::new constMark Mansi-1/+1
2018-04-22Implement From for more types on CowGeorge Burton-0/+7
2018-04-21Add some f32 and f64 inherent methods in libcoreSimon Sapin-0/+1
… previously in the unstable core::num::Float trait. Per https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183, the `abs`, `signum`, and `powi` methods are *not* included for now since they rely on LLVM intrinsics and we haven’t determined yet whether those instrinsics lower to calls to libm functions on any platform.
2018-04-17Rollup merge of #49555 - nox:inline-into-boxed, r=alexcrichtonkennytm-1/+3
Inline most of the code paths for conversions with boxed slices This helps with the specific problem described in #49541, obviously without making any large change to how inlining works in the general case. Everything involved in the conversions is made `#[inline]`, except for the `<Vec<T>>::into_boxed_slice` entry point which is made `#[inline(always)]` after checking that duplicating the function mentioned in the issue prevented its inlining if I only annotate it with `#[inline]`. For the record, that function was: ```rust pub fn foo() -> Box<[u8]> { vec![0].into_boxed_slice() } ``` To help the inliner's job, we also hoist a `self.capacity() != self.len` check in `<Vec<T>>::shrink_to_fit` and mark it as `#[inline]` too.
2018-04-16Auto merge of #48945 - clarcharr:iter_exhaust, r=Kimundibors-6/+3
Replace manual iterator exhaust with for_each(drop) This originally added a dedicated method, `Iterator::exhaust`, and has since been replaced with `for_each(drop)`, which is more idiomatic. <del>This is just shorthand for `for _ in &mut self {}` or `while let Some(_) = self.next() {}`. This states the intent a lot more clearly than the identical code: run the iterator to completion. <del>At least personally, my eyes tend to gloss over `for _ in &mut self {}` without fully paying attention to what it does; having a `Drop` implementation akin to: <del>`for _ in &mut self {}; unsafe { free(self.ptr); }`</del> <del>Is not as clear as: <del>`self.exhaust(); unsafe { free(self.ptr); }` <del>Additionally, I've seen debate over whether `while let Some(_) = self.next() {}` or `for _ in &mut self {}` is more clear, whereas `self.exhaust()` is clearer than both.
2018-04-15Remove #[inline(always)] on Vec::into_boxed_sliceAnthony Ramine-1/+0
2018-04-14Cleanup liballoc use statementsMike Hommey-1/+1
Some modules were still using the deprecated `allocator` module, use the `alloc` module instead. Some modules were using `super` while it's not needed. Some modules were more or less ordering them, and other not, so the latter have been modified to match the others.
2018-04-12Auto merge of #49551 - scottmcm:deprecate-offset_to, r=KodrAusbors-3/+4
Deprecate offset_to; switch core&alloc to using offset_from instead Bonus: might make code than uses `.len()` on slice iterators faster cc https://github.com/rust-lang/rust/issues/41079
2018-04-08Remove inline on Vec::shrink_to_fit as asked by AlexAnthony Ramine-1/+0
2018-04-05Rollup merge of #49496 - glandium:master, r=sfacklerkennytm-26/+55
Add more vec![... ; n] optimizations vec![0; n], via implementations of SpecFromElem, has an optimization that uses with_capacity_zeroed instead of with_capacity, which will use calloc instead of malloc, and avoid an extra memset. This PR adds the same optimization for ptr::null, ptr::null_mut, and None, when their in-memory representation is zeroes.
2018-04-04Replace manual iter exhaust with for_each(drop).Clar Charr-6/+3
2018-04-04Rollup merge of #49559 - djc:resize-with, r=TimNNkennytm-7/+57
Introduce Vec::resize_with method (see #41758) In #41758, the libs team decided they preferred `Vec::resize_with` over `Vec::resize_default()`. Here is an implementation to get this moving forward. I don't know what the removal process for `Vec::resize_default()` should be, so I've left it in place for now. Would be happy to follow up with its removal.
2018-04-03Introduce Vec::resize_with method (see #41758)Dirkjan Ochtman-7/+57
2018-04-03Remove all unstable placement featuresAidan Hobson Sayers-75/+1
Closes #22181, #27779
2018-04-02Add vec!['\0'; n] optimization, like vec![0; n]Mike Hommey-0/+2
Similarly to vec![ptr::null{,_mut}(); n] in previous change, this adds the optimization for vec!['\0'; n].
2018-04-02Add vec![ptr::null{,_mut}(); n] optimization, like vec![0; n]Mike Hommey-26/+53
vec![0; n], via implementations of SpecFromElem, has an optimization that uses with_capacity_zeroed instead of with_capacity, which will use calloc instead of malloc, and avoid an extra memset. This adds the same optimization for vec![ptr::null(); n] and vec![ptr::null_mut(); n], assuming their bit value is 0 (which is true on all currently supported platforms). This does so by adding an intermediate trait IsZero, which looks very much like nonzero::Zeroable, but that one is on the way out, and doesn't apply to pointers anyways. Adding such a trait allows to avoid repeating the logic using with_capacity_zeroed or with_capacity, or making the macro more complex to support generics.
2018-04-01Inline most of the code paths for conversions with boxed slicesAnthony Ramine-1/+5
This helps with the specific problem described in #49541, obviously without making any large change to how inlining works in the general case. Everything involved in the conversions is made `#[inline]`, except for the `<Vec<T>>::into_boxed_slice` entry point which is made `#[inline(always)]` after checking that duplicating the function mentioned in the issue prevented its inlining if I only annotate it with `#[inline]`. For the record, that function was: ```rust pub fn foo() -> Box<[u8]> { vec![0].into_boxed_slice() } ``` To help the inliner's job, we also hoist a `self.capacity() != self.len` check in `<Vec<T>>::shrink_to_fit` and mark it as `#[inline]` too.
2018-03-31Deprecate offset_to; switch core&alloc to using offset_from insteadScott McMurray-3/+4
Bonus: might make code than uses `.len()` on slice iterators faster
2018-03-30Rollup merge of #49466 - glandium:master, r=rkruppekennytm-2/+2
Use f{32,64}::to_bits for is_zero test in vec::SpecFromElem vec::SpecFromElem provides an optimization to use calloc to fill a Vec when the element given to fill the Vec is represented by 0. For floats, the test for that currently used is `x == 0. && x.is_sign_positive()`. When compiled in a standalone function, rustc generates the following assembly: ``` xorps xmm1, xmm1 ucomisd xmm0, xmm1 setnp al sete cl and cl, al movq rax, xmm0 test rax, rax setns al and al, cl ret ``` A simpler test telling us whether the value is represented by 0, is `x.to_bits() == 0`, which rustc compiles to: ``` movq rax, xmm0 test rax, rax sete al ret ``` Not that the test is hot in any way, but it also makes it clearer what the intent in the rust code is.
2018-03-29Move RangeArguments to {core::std}::ops and rename to RangeBoundsSimon Sapin-4/+3
These unstable items are deprecated: * The `std::collections::range::RangeArgument` reexport * The `std::collections::range` module.
2018-03-29Move alloc::Bound to {core,std}::opsSimon Sapin-1/+1
The stable reexport `std::collections::Bound` is now deprecated. Another deprecated reexport could be added in `alloc`, but that crate is unstable.
2018-03-29Use f{32,64}::to_bits for is_zero test in vec::SpecFromElemMike Hommey-2/+2
vec::SpecFromElem provides an optimization to use calloc to fill a Vec when the element given to fill the Vec is represented by 0. For floats, the test for that currently used is `x == 0. && x.is_sign_positive()`. When compiled in a standalone function, rustc generates the following assembly: ``` xorps xmm1, xmm1 ucomisd xmm0, xmm1 setnp al sete cl and cl, al movq rax, xmm0 test rax, rax setns al and al, cl ret ``` A simpler test telling us whether the value is represented by 0, is `x.to_bits() == 0`, which rustc compiles to: ``` movq rax, xmm0 test rax, rax sete al ret ``` Not that the test is hot in any way, but it also makes it clearer what the intent in the rust code is.
2018-03-28Rollup merge of #49452 - frewsxcv:frewsxcv-vec-cap-len, r=dtolnaykennytm-3/+4
Clarify "length" wording in `Vec::with_capacity`. Fixes https://github.com/rust-lang/rust/issues/49448.
2018-03-28Clarify "length" wording in `Vec::with_capacity`.Corey Farwell-3/+4
2018-03-27Implement `shrink_to` method on collectionsDiggory Blake-1/+26
2018-03-14implementing fallible allocation API (try_reserve) for Vec, String and HashMapsnf-0/+78
2018-03-09Add missing urlsGuillaume Gomez-7/+14
2018-03-06Rollup merge of #47463 - bluss:fused-iterator, r=alexcrichtonkennytm-2/+2
Stabilize FusedIterator FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate. Closes #35602
2018-03-03core: Update stability attributes for FusedIteratorUlrik Sverdrup-2/+2
2018-03-03core: Stabilize FusedIteratorUlrik Sverdrup-2/+2
FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate.
2018-03-02Don't have Vec<T> delegate to [T]'s bounds for indexingJonathan Behrens-7/+11
2018-03-02Update commentsJonathan Behrens-2/+2
2018-03-02Have Vec use slice's implementations of Index<I> and IndexMut<I>Jonathan Behrens-125/+5
2018-02-22[docs] Minor wording changes to drain_filter docsMatt Brubeck-2/+2
The docs currently say, "If the closure returns false, it will try again, and call the closure on the next element." But this happens regardless of whether the closure returns true or false.
2018-02-16Clarify contiguity of Vec's elements.Sergio Benitez-5/+5
2018-02-13Switch to retain calling drain_filter.Jacob Kiesel-21/+1
2018-02-08Swap `ptr::read` for `ptr::drop_in_place`Jacob Kiesel-1/+1
2018-02-07Apply optimization from #44355 to retainJacob Kiesel-4/+9
2018-01-24Auto merge of #47299 - cramertj:unsafe-placer, r=alexcrichtonbors-1/+1
Make core::ops::Place an unsafe trait Consumers of `Place` would reasonably expect that the `pointer` function returns a valid pointer to memory that can actually be written to.