about summary refs log tree commit diff
path: root/src/liballoc/tests
AgeCommit message (Collapse)AuthorLines
2020-07-27mv std libs to library/mark-11736/+0
2020-07-24Rollup merge of #74677 - ssomers:btree_cleanup_2, r=AmanieuYuki Okushi-12/+46
Remove needless unsafety from BTreeMap::drain_filter Remove one piece of unsafe code in the iteration over the iterator returned by BTreeMap::drain_filter. - Changes an explicitly unspecified part of the API: when the user-supplied predicate (or some of BTreeMap's code) panicked, and the caller tries to use the iterator again, we no longer offer the same key/value pair to the predicate again but pretend the iterator has finished. Note that Miri does not find UB in the test case added here with the unsafe code (or without). - Makes the code a little easier on the eyes. - Makes the code a little harder on the CPU: ``` benchcmp c0 c2 --threshold 3 name c0 ns/iter c2 ns/iter diff ns/iter diff % speedup btree::set::clone_100_and_drain_all 2,794 2,900 106 3.79% x 0.96 btree::set::clone_100_and_drain_half 2,604 2,964 360 13.82% x 0.88 btree::set::clone_10k_and_drain_half 287,770 322,755 34,985 12.16% x 0.89 ``` r? @Amanieu
2020-07-23BTreeMap::drain_filter: replace needless unsafety and testStein Somers-12/+46
2020-07-22More BTreeMap test cases, some exposing undefined behaviourStein Somers-0/+80
2020-07-02disable BTree min_max test in Miri for nowRalf Jung-0/+1
2020-07-01Rollup merge of #73466 - matthiaskrgr:char_into_string, r=dtolnayManish Goregaokar-0/+7
impl From<char> for String This allows us to write ````rust fn char_to_string() -> String { 'a'.into() } ```` which was not possible before.
2020-06-26Shortcuts for min/max on ordinary BTreeMap/BTreeSet iteratorsStein Somers-0/+66
2020-06-22Rollup merge of #71660 - sollyucko:master, r=dtolnayDylan DPC-0/+54
impl PartialEq<Vec<B>> for &[A], &mut [A] https://github.com/rust-lang/rfcs/issues/2917
2020-06-20impl PartialEq<Vec<B>> for &[A], &mut [A]Solomon Ucko-0/+54
2020-06-20Remove uses of `Vec::remove_item`Lukas Kalbertodt-16/+0
2020-06-18add test for char into stringMatthias Krüger-0/+7
2020-06-10Migrate to numeric associated constsLzu Tao-11/+11
2020-06-05Use assert_eq for liballoc testIvan Tham-1/+1
2020-05-29Remove flaky test and document the other's flakinessmendess-8/+5
2020-05-23Add testsmendess-0/+36
2020-05-19Auto merge of #72227 - nnethercote:tiny-vecs-are-dumb, r=Amanieubors-0/+115
Tiny Vecs are dumb. Currently, if you repeatedly push to an empty vector, the capacity growth sequence is 0, 1, 2, 4, 8, 16, etc. This commit changes the relevant code (the "amortized" growth strategy) to skip 1 and 2, instead using 0, 4, 8, 16, etc. (You can still get a capacity of 1 or 2 using the "exact" growth strategy, e.g. via `reserve_exact()`.) This idea (along with the phrase "tiny Vecs are dumb") comes from the "doubling" growth strategy that was removed from `RawVec` in #72013. That strategy was barely ever used -- only when a `VecDeque` was grown, oddly enough -- which is why it was removed in #72013. (Fun fact: until just a few days ago, I thought the "doubling" strategy was used for repeated push case. In other words, this commit makes `Vec`s behave the way I always thought they behaved.) This change reduces the number of allocations done by rustc itself by 10% or more. It speeds up rustc, and will also speed up any other Rust program that uses `Vec`s a lot. In theory, the change could increase memory usage, but in practice it doesn't. It would be an unusual program where very small `Vec`s having a capacity of 4 rather than 1 or 2 would make a difference. You'd need a *lot* of very small `Vec`s, and/or some very small `Vec`s with very large elements. r? @Amanieu
2020-05-19Auto merge of #71447 - cuviper:unsized_cow, r=dtolnaybors-0/+48
impl From<Cow> for Box, Rc, and Arc These forward `Borrowed`/`Owned` values to existing `From` impls. - `Box<T>` is a fundamental type, so it would be a breaking change to add a blanket impl. Therefore, `From<Cow>` is only implemented for `[T]`, `str`, `CStr`, `OsStr`, and `Path`. - For `Rc<T>` and `Arc<T>`, `From<Cow>` is implemented for everything that implements `From` the borrowed and owned types separately.
2020-05-18Tiny Vecs are dumb.Nicholas Nethercote-0/+115
Currently, if you repeatedly push to an empty vector, the capacity growth sequence is 0, 1, 2, 4, 8, 16, etc. This commit changes the relevant code (the "amortized" growth strategy) to skip 1 and 2 in most cases, instead using 0, 4, 8, 16, etc. (You can still get a capacity of 1 or 2 using the "exact" growth strategy, e.g. via `reserve_exact()`.) This idea (along with the phrase "tiny Vecs are dumb") comes from the "doubling" growth strategy that was removed from `RawVec` in #72013. That strategy was barely ever used -- only when a `VecDeque` was grown, oddly enough -- which is why it was removed in #72013. (Fun fact: until just a few days ago, I thought the "doubling" strategy was used for repeated push case. In other words, this commit makes `Vec`s behave the way I always thought they behaved.) This change reduces the number of allocations done by rustc itself by 10% or more. It speeds up rustc, and will also speed up any other Rust program that uses `Vec`s a lot.
2020-04-25Rollup merge of #71485 - arlopurcell:binary_heap_retain, r=AmanieuDylan DPC-0/+9
Add BinaryHeap::retain as suggested in #42849 This PR implements retain for BinaryHeap as suggested in #42849. This is my first PR for Rust, so please let me know if I should be doing anything differently, thanks!
2020-04-24Add BinaryHeap::retain as suggested in #42849arlo-0/+9
2020-04-23liballoc: more compact way to adjust test sizes for MiriRalf Jung-67/+33
2020-04-22Add tests from CowJosh Stone-0/+48
2020-04-09Disable try_reserve tests on AndroidAmanieu d'Antras-0/+6
2020-04-06Use usize::MAX as assoc const in liballocLinus Färnstrand-1/+1
2020-04-06Use assoc const f32::NAN in liballocLinus Färnstrand-2/+2
2020-04-05Rollup merge of #70777 - faern:use-assoc-int-consts2, r=dtolnayDylan DPC-3/+0
Don't import integer and float modules, use assoc consts Stop importing the standard library integer and float modules to reach the `MIN`, `MAX` and other constants. They are available directly on the primitive types now. This PR is a follow up of #69860 which made sure we use the new constants in documentation. This type of change touches a lot of files, and previously all my assoc int consts PRs had collisions and were accepted only after a long delay. So I'd prefer to do it in smaller steps now. Just removing these imports seem like a good next step. r? @dtolnay
2020-04-05Rollup merge of #70558 - RalfJung:vec-extend-aliasing, r=AmanieuDylan DPC-5/+66
Fix some aliasing issues in Vec `Vec::extend` and `Vec::truncate` invalidated references into the vector even without reallocation, because they (implicitly) created a mutable reference covering the *entire* initialized part of the vector. Fixes https://github.com/rust-lang/rust/issues/70301 I verified the fix by adding some new tests here that I ran in Miri.
2020-04-05Stop importing integer modules in liballocLinus Färnstrand-3/+0
2020-04-02Auto merge of #70362 - TimDiekmann:alloc-overhaul, r=Amanieubors-2/+8
Overhaul of the `AllocRef` trait to match allocator-wg's latest consens; Take 2 GitHub won't let me reopen #69889 so I make a new PR. In addition to #69889 this fixes the unsoundness of `RawVec::into_box` when using allocators supporting overallocating. Also it uses `MemoryBlock` in `AllocRef` to unify `_in_place` methods by passing `&mut MemoryBlock`. Additionally, `RawVec` now checks for `size_of::<T>()` again and ignore every ZST. The internal capacity of `RawVec` isn't used by ZSTs anymore, as `into_box` now requires a length to be specified. r? @Amanieu fixes rust-lang/wg-allocators#38 fixes rust-lang/wg-allocators#41 fixes rust-lang/wg-allocators#44 fixes rust-lang/wg-allocators#51
2020-04-01Rollup merge of #68770 - ssomers:btree_drain_filter, r=AmanieuDylan DPC-1/+340
BTreeMap/BTreeSet: implement drain_filter Provide an implementation of drain_filter for BTreeMap and BTreeSet. Should be optimal when the predicate picks only elements in leaf nodes with at least MIN_LEN remaining elements, which is a common case, at least when draining only a fraction of the map/set, and also when the predicate picks elements stored in internal nodes where the right subtree can easily let go of a replacement element. The first commit adds benchmarks with an external, naive implementation. to compare how much this claimed optimality-in-some-cases is actually worth.
2020-03-30fix and test aliasing in swap_removeRalf Jung-0/+5
2020-03-30fix aliasing in remove()Ralf Jung-1/+6
also add smoke test to detect relocation even in rustc runs
2020-03-30also cover next() path of draining iteratorsRalf Jung-4/+11
2020-03-30test more mutating vector methodsRalf Jung-0/+30
2020-03-30fix BTreeMap test compilation with MiriRalf Jung-1/+1
2020-03-30add some testsRalf Jung-4/+18
2020-03-29BTreeMap/BTreeSet: implement and test drain_filterStein Somers-1/+340
2020-03-28BTreeMap testing: introduce symbolic constants and refer to height consistently.Stein Somers-41/+49
2020-03-28Make fields in `MemoryBlock` publicTim Diekmann-1/+1
2020-03-26Remove alignment from `MemoryBlock`Tim Diekmann-5/+2
2020-03-26Fix issues from review and unsoundness of `RawVec::into_box`Tim Diekmann-3/+6
2020-03-26Overhaul of the `AllocRef` trait to match allocator-wg's latest consensTim Diekmann-2/+8
2020-03-24must_use on split_offKornel-2/+2
#70194
2020-03-20Update test commentary for shared root removalMark Rousskov-9/+2
2020-03-08Rollup merge of #69776 - ssomers:fix69769, r=Mark-SimulacrumMazdak Farrokhzad-1/+25
Fix & test leak of some BTreeMap nodes on panic during `into_iter` Fixes #69769
2020-03-06Fix & test leak of some BTreeMap nodes on panic during `into_iter`Stein Somers-1/+25
2020-03-05reduce test size for MiriRalf Jung-2/+2
2020-03-03Rollup merge of #69609 - TimDiekmann:excess, r=AmanieuYuki Okushi-1/+1
Remove `usable_size` APIs This removes the usable size APIs: - remove `usable_size` (obv) - change return type of allocating methods to include the allocated size - remove `_excess` API r? @Amanieu closes rust-lang/wg-allocators#17
2020-03-03Remove `usable_size` APIsTim Diekmann-1/+1
2020-02-26Auto merge of #67290 - jonas-schievink:leak-audit, r=KodrAusbors-2/+267
Audit liballoc for leaks in `Drop` impls when user destructor panics Inspired by https://github.com/rust-lang/rust/pull/67243 and https://github.com/rust-lang/rust/pull/67235, this audits and hopefully fixes the remaining `Drop` impls in liballoc for resource leaks in the presence of panics in destructors called by the affected `Drop` impl. This does not touch `Hash{Map,Set}` since they live in hashbrown. They have similar issues though. r? @KodrAus