about summary refs log tree commit diff
path: root/src/liballoc/vec.rs
AgeCommit message (Collapse)AuthorLines
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.
2018-01-20Rename std::ptr::Shared to NonNullSimon Sapin-5/+5
`Shared` is now a deprecated `type` alias. CC https://github.com/rust-lang/rust/issues/27730#issuecomment-352800629
2018-01-09Make core::ops::Place an unsafe traitTaylor Cramer-1/+1
2018-01-01Fix panic condition docs for Vec::insert.Corey Farwell-1/+1
Fixes https://github.com/rust-lang/rust/issues/47065.
2017-12-20Clarify vec docs on deallocation (fixes #46879)Manish Goregaokar-2/+4
2017-12-16Move PhantomData<T> from Shared<T> to users of both Shared and #[may_dangle]Simon Sapin-0/+3
After discussing [1] today with @pnkfelix and @Gankro, we concluded that it’s ok for drop checking not to be much smarter than the current `#[may_dangle]` design which requires an explicit unsafe opt-in. [1] https://github.com/rust-lang/rust/issues/27730#issuecomment-316432083
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-4/+1
2017-11-21fix some typosMartin Lindhe-1/+1
2017-11-03Remove unused AsciiExt imports and fix tests related to ascii methodsLukas Kalbertodt-2/+0
Many AsciiExt imports have become useless thanks to the inherent ascii methods added in the last commits. These were removed. In some places, I fully specified the ascii method being called to enforce usage of the AsciiExt trait. Note that some imports are not removed but tagged with a `#[cfg(stage0)]` attribute. This is necessary, because certain ascii methods are not yet available in stage0. All those imports will be removed later. Additionally, failing tests were fixed. The test suite should exit successfully now.
2017-10-09usize index message for vecGuillaume Gomez-1/+24
2017-10-01Resolves #36284 - vec.rs documentationSean Prashad-5/+1
2017-09-24Backport libs stabilizations to 1.21 betaDavid Tolnay-6/+6
This includes the following stabilizations: - tcpstream_connect_timeout https://github.com/rust-lang/rust/pull/44563 - iterator_for_each https://github.com/rust-lang/rust/pull/44567 - ord_max_min https://github.com/rust-lang/rust/pull/44593 - compiler_fences https://github.com/rust-lang/rust/pull/44595 - needs_drop https://github.com/rust-lang/rust/pull/44639 - vec_splice https://github.com/rust-lang/rust/pull/44640
2017-09-20Auto merge of #44355 - Xaeroxe:optimize_drain_filter, r=alexcrichtonbors-1/+7
Optimize drain_filter This PR cuts out two copies from each iteration of `drain_filter` by exchanging the swap operation for a copy_nonoverlapping function call instead. Since the data being swapped is not needed anymore we can just overwrite it instead.
2017-09-18Add requested commentJacob Kiesel-0/+3
2017-09-17stabilized vec_splice (fixes #32310)Michal Budzynski-7/+6