about summary refs log tree commit diff
path: root/library/alloc/tests/vec.rs
AgeCommit message (Collapse)AuthorLines
2021-09-30implement advance_(back_)_by on more iteratorsThe8472-0/+18
2021-08-07Use assert_matches! instead of if let {} elseKornel-113/+103
2021-07-24Hide allocator details from TryReserveErrorKornel-33/+76
2021-06-18Lint for unused borrows as part of UNUSED_MUST_USEhi-rustin-5/+5
2021-06-02Update expressions where we can use array's IntoIterator implementationMuhammad Mominul Huque-5/+5
2021-05-24Make Vec::dedup panicking test actually detect double panicsGiacomo Stevanato-23/+25
2021-05-19from review: more robust testthe8472-2/+2
This also checks the contents and not only the capacity in case IntoIter's clone implementation is changed to add capacity at the end. Extra capacity at the beginning would be needed to make InPlaceIterable work. Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
2021-05-19add regression testThe8472-0/+12
2021-05-19remove InPlaceIterable marker from Peekable due to unsoundnessThe8472-1/+0
The unsoundness is not in Peekable per se, it rather is due to the interaction between Peekable being able to hold an extra item and vec::IntoIter's clone implementation shortening the allocation. An alternative solution would be to change IntoIter's clone implementation to keep enough spare capacity available.
2021-04-04Rollup merge of #83827 - the8472:fix-inplace-panic-on-drop, r=RalfJungDylan DPC-1/+10
cleanup leak after test to make miri happy Contains changes that were requested in #83629 but didn't make it into the rollup. r? `````@RalfJung`````
2021-04-04Rollup merge of #81619 - SkiFire13:resultshunt-inplace, r=the8472Dylan DPC-2/+2
Implement `SourceIterator` and `InPlaceIterable` for `ResultShunt`
2021-04-04suggestion from reviewthe8472-1/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-04-04cleanup leak after test to make miri happyThe8472-1/+10
2021-03-29add testcase for double-drop during Vec in-place collectionThe8472-1/+37
2021-03-16Vec::dedup optimization - add benchesSoveu-1/+1
2021-03-15Merge branch 'master' into dedupSoveu-0/+45
2021-03-15Vec::dedup optimization - add test for panicSoveu-0/+54
2021-03-15Vec::dedup optimization - add testsSoveu-0/+73
2021-03-04Add regression test for `Vec::extend_from_within` leakWaffle-0/+42
2021-03-03Add test that Vec::spare_capacity_mut doesn't invalidate pointersWaffle-0/+4
2021-02-13Added tests to drain an empty vecHanif Bin Ariffin-0/+11
Discovered this kind of issue in an unrelated library. The author copied the tests from here and AFAIK, there are no tests for this particular case. Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
2021-02-11Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-sebors-0/+61
Optimize Vec::retain Use `copy_non_overlapping` instead of `swap` to reduce memory writes, like what we've done in #44355 and `String::retain`. #48065 already tried to do this optimization but it is reverted in #67300 due to bad codegen of `DrainFilter::drop`. This PR re-implement the drop-then-move approach. I did a [benchmark](https://gist.github.com/oxalica/3360eec9376f22533fcecff02798b698) on small-no-drop, small-need-drop, large-no-drop elements with different predicate functions. It turns out that the new implementation is >20% faster in average for almost all cases. Only 2/24 cases are slower by 3% and 5%. See the link above for more detail. I think regression in may-panic cases is due to drop-guard preventing some optimization. If it's permitted to leak elements when predicate function of element's `drop` panic, the new implementation should be almost always faster than current one. I'm not sure if we should leak on panic, since there is indeed an issue (#52267) complains about it before.
2021-02-03Update test to collect item with a different type than the original vecGiacomo Stevanato-1/+1
2021-02-01Move testGiacomo Stevanato-2/+2
2021-01-31add `Vec::extend_from_within` methodWaffle-0/+70
Implement <https://github.com/rust-lang/rfcs/pull/2714>, changes from the RFC: - Rename the method `append_from_within` => `extend_from_within` - Loose :Copy bound => :Clone - Specialize in case of :Copy This commit also adds `Vec::split_at_spare` private method and use it to implement `Vec::spare_capacity_mut` and `Vec::extend_from_within`. This method returns 2 slices - initialized elements (same as `&mut vec[..]`) and uninitialized but allocated space (same as `vec.spare_capacity_mut()`).
2021-01-24Simplify and fix testsoxalica-51/+40
2021-01-18Optimize Vec::retainoxalica-0/+72
2020-11-26Fix new 'unnecessary trailing semicolon' warningsAaron Hill-3/+3
2020-10-17Move vec swap testAlexis Bourget-1/+13
2020-10-17Move vec-macro-repeat testAlexis Bourget-0/+13
2020-10-17Move zero-sized-vec-push testAlexis Bourget-0/+17
2020-10-07Auto merge of #74194 - mbrubeck:slice-eq, r=sfacklerbors-1/+2
Add PartialEq impls for Vec <-> slice This is a follow-up to #71660 and rust-lang/rfcs#2917 to add two more missing vec/slice PartialEq impls: ``` impl<A, B> PartialEq<[B]> for Vec<A> where A: PartialEq<B> { .. } impl<A, B> PartialEq<Vec<B>> for [A] where A: PartialEq<B> { .. } ``` Since this is insta-stable, it should go through the `@rust-lang/libs` FCP process. Note that I used version 1.47.0 for the `stable` attribute because I assume this will not merge before the 1.46.0 branch is cut next week.
2020-09-21Move vec-cycle-wrapped testAlexis Bourget-0/+41
2020-09-21Move vec-cycle testAlexis Bourget-0/+39
2020-09-19Use `T::BITS` instead of `size_of::<T> * 8`.Mara Bos-1/+1
2020-09-16Rollup merge of #76662 - RalfJung:lib-test-miri, r=Mark-SimulacrumRalf Jung-1/+1
Fix liballoc test suite for Miri Mostly, fix the regression introduced by https://github.com/rust-lang/rust/pull/75207 that caused slices (i.e., references) to be created to invalid memory or memory that has aliasing pointers that we want to keep valid. @dylni this changes the type of `check_range` to only require the length, not the full reference to the slice, which indeed is all the information this function requires. Also reduce the size of a test introduced in https://github.com/rust-lang/rust/pull/70793 to make it not take 3 minutes in Miri. This makes https://github.com/RalfJung/miri-test-libstd work again.
2020-09-16Rollup merge of #75146 - tmiasko:range-overflow, r=Mark-SimulacrumDylan DPC-0/+25
Detect overflow in proc_macro_server subspan * Detect overflow in proc_macro_server subspan * Add tests for overflow in Vec::drain * Add tests for overflow in String / VecDeque operations using ranges
2020-09-15fix slice::check_range aliasing problemsRalf Jung-1/+1
2020-09-15reduce size of test_from_iter_specialization_with_iterator_adapters test in MiriRalf Jung-1/+1
2020-09-15Auto merge of #76682 - richkadel:vec-take, r=Mark-Simulacrumbors-0/+14
Optimize behavior of vec.split_off(0) (take all) Optimization improvement to `split_off()` so the performance meets the intuitively expected behavior when `at == 0`, avoiding the current behavior of copying the entire vector. The change honors documented behavior that the original vector's "previous capacity unchanged". This improvement better supports the pattern for building and flushing a buffer of elements, such as the following: ```rust let mut vec = Vec::new(); loop { vec.push(something); if condition_is_met { process(vec.split_off(0)); } } ``` `Option` wrapping is the first alternative I thought of, but is much less obvious and more verbose: ```rust let mut capacity = 1; let mut vec: Option<Vec<Stuff>> = None; loop { vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something); if condition_is_met { capacity = vec.capacity(); process(vec.take().unwrap()); } } ``` Directly using `mem::replace()` (instead of calling`split_off()`) could work, but `mem::replace()` is a more advanced tool for Rust developers, and in this case, I believe developers would assume the standard library should be sufficient for the purpose described here. The benefit of the approach to this change is it does not change the existing API contract, but improves the peformance of `split_off(0)` for `Vec`, `String` (which delegates `split_off()` to `Vec`), and any other existing use cases. This change adds tests to validate the behavior of `split_off()` with regard to capacity, as originally documented, and confirm that behavior still holds, when `at == 0`. The change is an implementation detail, and does not require a documentation change, but documenting the new behavior as part of its API contract may benefit future users. (Let me know if I should make that documentation update.) Note, for future consideration: I think it would be helpful to introduce an additional method to `Vec` (if not also to `String`): ``` pub fn take_all(&mut self) -> Self { self.split_off(0) } ``` This would make it more clear how `Vec` supports the pattern, and make it easier to find, since the behavior is similar to other `take()` methods in the Rust standard library. r? `@wesleywiser` FYI: `@tmandry`
2020-09-13Optimize behavior of vec.split_off(0) (take all)Rich Kadel-0/+14
Optimization improvement to `split_off()` so the performance meets the intuitively expected behavior when `at == 0`, avoiding the current behavior of copying the entire vector. The change honors documented behavior that the method leaves the original vector's "previous capacity unchanged". This improvement better supports the pattern for building and flushing a buffer of elements, such as the following: ```rust let mut vec = Vec::new(); loop { vec.push(something); if condition_is_met { process(vec.split_off(0)); } } ``` `Option` wrapping is the first alternative I thought of, but is much less obvious and more verbose: ```rust let mut capacity = 1; let mut vec: Option<Vec<Stuff>> = None; loop { vec.get_or_insert_with(|| Vec::with_capacity(capacity)).push(something); if condition_is_met { capacity = vec.capacity(); process(vec.take().unwrap()); } } ``` Directly applying `mem::replace()` could work, but `mem::` functions are typically a last resort, when a developer is actively seeking better performance than the standard library provides, for example. The benefit of the approach to this change is it does not change the existing API contract, but improves the peformance of `split_off(0)` for `Vec`, `String` (which delegates `split_off()` to `Vec`), and any other existing use cases. This change adds tests to validate the behavior of `split_off()` with regard to capacity, as originally documented, and confirm that behavior still holds, when `at == 0`. The change is an implementation detail, and does not require a documentation change, but documenting the new behavior as part of its API contract may benefit future users. (Let me know if I should make that documentation update.) Note, for future consideration: I think it would be helpful to introduce an additional method to `Vec` (if not also to `String`): ``` pub fn take_all(&mut self) -> Self { self.split_off(0) } ``` This would make it more clear how `Vec` supports the pattern, and make it easier to find, since the behavior is similar to other `take()` methods in the Rust standard library.
2020-09-13note that test_stable_pointers does not reflect a stable guaranteeRalf Jung-0/+3
2020-09-07Rollup merge of #76324 - ayushmishra2005:move_vec_tests_in_library, r=matkladDylan DPC-0/+23
Move Vec slice UI tests in library Moved some of Vec slice UI tests in Library as a part of #76268 r? @matklad
2020-09-07Rollup merge of #76273 - CraftSpider:master, r=matkladDylan DPC-0/+56
Move some Vec UI tests into alloc unit tests A bit of work towards #76268, makes a number of the Vec UI tests that are simply running code into unit tests. Ensured that they are being run when testing liballoc locally.
2020-09-04Move Vec slice UI tests in libraryAyush Kumar Mishra-0/+23
2020-09-04Add tests for overflow in Vec::drainTomasz Miąsko-0/+25
2020-09-03Remove vec-to_str.rs, merge the remaining test in with vecRune Tynan-0/+3
2020-09-03remove empty Vec extend optimizationThe8472-10/+0
The optimization meant that every extend code path had to emit llvm IR for from_iter and extend spec_extend, which likely impacts compile times while only improving a few edge-cases
2020-09-03support in-place collect for MapWhile adaptersThe8472-0/+1
2020-09-03generalize in-place collect to types of same size and alignmentThe8472-2/+3