about summary refs log tree commit diff
path: root/library/alloc
AgeCommit message (Collapse)AuthorLines
2021-08-28add benchmark for From<[T; N]> in VecDequeCheng XU-0/+15
2021-08-28BTreeSet::from_iter: use bulk building to improve the performanceCheng XU-5/+22
Apply the same optimization as BTreeMap::from_iter.
2021-08-28BTreeMap::from_iter: use bulk building to improve the performanceCheng XU-5/+79
Bulk building is a common technique to increase the performance of building a fresh btree map. Instead of inserting items one-by-one, we sort all the items beforehand then create the BtreeMap in bulk.
2021-08-28add benchmark for BTreeMap::from_iterCheng XU-0/+50
2021-08-28Fix a typo in raw_vecterrarier2111-1/+1
2021-08-26Add missing # Panics section to `Vec` methodSebastian Widua-1/+6
namely `Vec::extend_from_within`
2021-08-26Rollup merge of #88216 - kornelski:from_layout_err, r=kennytmManish Goregaokar-3/+3
Don't stabilize creation of TryReserveError instances #48043 + https://github.com/rust-lang/rust/pull/87993#issuecomment-903189016
2021-08-25Rollup merge of #88293 - est31:fix_grammar, r=Mark-SimulacrumLéo Lanteri Thauvin-4/+4
Fix grammar in alloc test
2021-08-25Rollup merge of #88226 - steffahn:an_rc, r=michaelwoeristerLéo Lanteri Thauvin-1/+1
Fix typo “a Rc” → “an Rc” (and a few more) After stumbling about it in the dev-guide, I’ve devided to eliminate all mentions of “a Rc”, replacing it with “an Rc”. E.g. ```plain $ rg "(^|[^'])\ba\b[^\w=:]*\bRc" compiler/rustc_data_structures/src/owning_ref/mod.rs 1149:/// Typedef of a owning reference that uses a `Rc` as the owner. library/std/src/ffi/os_str.rs 919: /// Converts a [`OsString`] into a [`Rc`]`<OsStr>` without copying or allocating. library/std/src/ffi/c_str.rs 961: /// Converts a [`CString`] into a [`Rc`]`<CStr>` without copying or allocating. src/doc/rustc-dev-guide/src/query.md 61:are cheaply cloneable; insert a `Rc` if necessary). src/doc/book/src/ch15-06-reference-cycles.md 72:decreases the reference count of the `a` `Rc<List>` instance from 2 to 1 as library/alloc/src/rc.rs 1746: /// Converts a generic type `T` into a `Rc<T>` ``` _(the match in the book is a false positive)_ Since the dev-guide is a submodule, it’s getting a separate PR: rust-lang/rustc-dev-guide#1191 I’ve also gone ahead and done the same search for `RwLock` and hit a few cases in the `OwningRef` adaption. Then, I couldn’t keep the countless cases of “a owning …” or “a owner” unaddressed, which concludes this PR. `@rustbot` label C-cleanup
2021-08-25Rollup merge of #88156 - steffahn:arc_make_mut_and_weak, r=Mark-SimulacrumLéo Lanteri Thauvin-19/+39
Adjust / fix documentation of `Arc::make_mut` Related discussion in the users forum: [Whatʼs this alleged difference between Arc::make_mut and Rc::make_mut? – The Rust Programming Language Forum](https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn) Also includes a small formatting improvement in the documentation of `Rc::make_mut`. This PR makes the two documentations in question complete analogs. The previously claimed point in which one “differs from the behavior of” the other turns out to be incorrect, AFAIK. One remaining inaccuracy: `Weak` pointers aren’t disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other. `@rustbot` label T-libs-api, A-docs
2021-08-24Make explanations of cross-references between `make_mut` and `get_mut` more ↵Frank Steffahn-4/+6
accurate
2021-08-24Clarifiy weak pointers being diassociated…Frank Steffahn-4/+6
…noting the fact that `clone` is not called. Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2021-08-24Fix grammarest31-4/+4
2021-08-24Fix typo “a Rc” → “an Rc”Frank Steffahn-1/+1
2021-08-22Fix typos “an”→“a” and a few different ones that appeared in the ↵Frank Steffahn-1/+1
same search
2021-08-22Fix typos “a”→“an”Frank Steffahn-1/+1
2021-08-21Auto merge of #88075 - Xuanwo:vec_deque_retain, r=dtolnaybors-8/+57
Optimize unnecessary check in VecDeque::retain This pr is highly inspired by https://github.com/rust-lang/rust/pull/88060 which shared the same idea: we can split the `for` loop into stages so that we can remove unnecessary checks like `del > 0`. ## Benchmarks Before ```rust test collections::vec_deque::tests::bench_retain_half_10000 ... bench: 290,125 ns/iter (+/- 8,717) test collections::vec_deque::tests::bench_retain_odd_10000 ... bench: 291,588 ns/iter (+/- 9,621) test collections::vec_deque::tests::bench_retain_whole_10000 ... bench: 287,426 ns/iter (+/- 9,009) ``` After ```rust test collections::vec_deque::tests::bench_retain_half_10000 ... bench: 243,940 ns/iter (+/- 8,563) test collections::vec_deque::tests::bench_retain_odd_10000 ... bench: 242,768 ns/iter (+/- 3,903) test collections::vec_deque::tests::bench_retain_whole_10000 ... bench: 202,926 ns/iter (+/- 6,332) ``` Based on the current benchmark, this PR will improve the perf of `VecDeque::retain` by around 16%. For special cases, the improvement will be up to 30%. Signed-off-by: Xuanwo <github@xuanwo.io>
2021-08-21Don't stabilize creation of TryReserveError instancesKornel-3/+3
2021-08-19Adjust documentation of `Arc::make_mut`Frank Steffahn-14/+30
Related discussion in the users forum: https://users.rust-lang.org/t/what-s-this-alleged-difference-between-arc-make-mut-and-rc-make-mut/63747?u=steffahn Also includes small formatting improvement in the documentation of `Rc::make_mut`. This commit makes the two documentations in question complete analogs. The previously claimed point in which one "differs from the behavior of" the other turns out to be incorrect, AFAIK. One remaining inaccuracy: `Weak` pointers aren't disassociated from the allocation but only from the contained value, i.e. in case of outstanding `Weak` pointers there still is a new allocation created, just the call to `.clone()` is avoided, instead the value is moved from one allocation to the other.
2021-08-18BTree: remove Ord bound from newGary Guo-44/+24
2021-08-17BTree: refine some commentsStein Somers-11/+9
2021-08-17Constified `Default` implementationsDeadbeef-15/+19
The libs-api team agrees to allow const_trait_impl to appear in the standard library as long as stable code cannot be broken (they are properly gated) this means if the compiler teams thinks it's okay, then it's okay. My priority on constifying would be: 1. Non-generic impls (e.g. Default) or generic impls with no bounds 2. Generic functions with bounds (that use const impls) 3. Generic impls with bounds 4. Impls for traits with associated types For people opening constification PRs: please cc me and/or oli-obk.
2021-08-16Rollup merge of #88030 - fee1-dead:fixme, r=oli-obkMara Bos-3/+1
Assign FIXMEs to me and remove obsolete ones Also fixed capitalization of documentation We also don't need to transform predicates to be non-const since we basically ignore const predicates in non-const contexts. r? `````@oli-obk`````
2021-08-16BTree: toughen panicky test of clone()Stein Somers-25/+32
2021-08-16Remove extra empty linesXuanwo-2/+0
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-08-16Optimize unnecessary check in VecDeque::retainXuanwo-8/+59
Signed-off-by: Xuanwo <github@xuanwo.io>
2021-08-16Auto merge of #87696 - ssomers:btree_lazy_iterator_cleanup, r=Mark-Simulacrumbors-56/+56
BTree: merge the complication introduced by #81486 and #86031 Also: - Deallocate the last few tree nodes as soon as an `into_iter` iterator steps beyond the end, instead of waiting around for the drop of the iterator (just to share more code). - Symmetric code for backward iteration. - Mark unsafe the methods on dying handles, modelling dying handles after raw pointers: it's the caller's responsibility to use them safely. r? `@Mark-Simulacrum`
2021-08-15Auto merge of #87974 - steffahn:slice_split_size_hints, r=dtolnaybors-0/+61
Test and fix `size_hint` for slice’s [r]split* iterators Adds extensive test (of `size_hint`) for all the _[r]split*_ iterators. Fixes `size_hint` upper bound for _split_inclusive*_ iterators which was one higher than necessary for non-empty slices. Fixes `size_hint` lower bound for _[r]splitn*_ iterators when _n == 0_, which was one too high. **Lower bound being one too high was a logic error, violating the correctness condition of `size_hint`.** _Edit:_ I’ve opened an issue for that bug, so this PR fixes #87978
2021-08-14Assign FIXMEs to me and remove obsolete onesDeadbeef-3/+1
Also fixed capitalization of documentation
2021-08-14Auto merge of #87913 - a1phyr:vec_spec_clone_from, r=dtolnaybors-10/+30
Specialize `Vec::clone_from` for `Copy` types This should improve performance and reduce code size. This also improves `clone_from` for `String`, `OsString` and `PathBuf`.
2021-08-13Improve wording, correct -> tight.Frank Steffahn-6/+6
2021-08-13Consistent use of `impl Trait` arguments in the test's helper function.Frank Steffahn-5/+1
2021-08-13allow incomplete features for nowDeadbeef-0/+2
2021-08-13Moved ui testDeadbeef-14/+56
2021-08-12Rewrite test from previous commit but without using macros.Frank Steffahn-64/+55
2021-08-12Test and fix size_hint for slice's [r]split* iteratorsFrank Steffahn-0/+74
Adds extensive test for all the [r]split* iterators. Fixes size_hint upper bound for split_inclusive* iterators which was one higher than necessary for non-empty slices. Fixes size_hint lower bound for [r]splitn* iterators when n==0, which was one too high.
2021-08-12Add missing cfg attributeBenoît du Garreau-0/+3
2021-08-12Auto merge of #87843 - kornelski:try_reserve, r=m-ou-sebors-292/+270
TryReserveErrorKind tests and inline A small follow-up to #87408
2021-08-10Specialize `Vec::clone_from` for `Copy` typesBenoît du Garreau-10/+27
This should improve performance and reduce code size. This also improves `clone_from` for `String`, `OsString` and `PathBuf`.
2021-08-08Auto merge of #86879 - YohDeadfall:stabilize-vec-shrink-to, r=dtolnaybors-8/+4
Stabilize Vec<T>::shrink_to This PR stabilizes `shrink_to` feature and closes the corresponding issue. The second point was addressed already, and no `panic!` should occur. Closes #56431.
2021-08-08Bump shrink_to stabilization to Rust 1.56David Tolnay-4/+4
2021-08-07Use assert_matches! instead of if let {} elseKornel-292/+269
2021-08-07Inline from of TryReserveErrorKindKornel-0/+1
2021-08-07Auto merge of #87408 - kornelski:try_reserve_error, r=yaahcbors-104/+252
Hide allocator details from TryReserveError I think there's [no need for TryReserveError to carry detailed information](https://github.com/rust-lang/rust/issues/48043#issuecomment-825139280), but I wouldn't want that issue to delay stabilization of the `try_reserve` feature. So I'm proposing to stabilize `try_reserve` with a `TryReserveError` as an opaque structure, and if needed, expose error details later. This PR moves the `enum` to an unstable inner `TryReserveErrorKind` that lives under a separate feature flag. `TryReserveErrorKind` could possibly be left as an implementation detail forever, and the `TryReserveError` get methods such as `allocation_size() -> Option<usize>` or `layout() -> Option<Layout>` instead, or the details could be dropped completely to make try-reserve errors just a unit struct, and thus smaller and cheaper.
2021-08-06Auto merge of #87777 - the8472:fix-mir-max-rss, r=oli-obk,joshtriplettbors-1/+65
Use zeroed allocations in the mir interpreter instead eagerly touching the memory #86255 introduced a 30% regression in [page faults](https://perf.rust-lang.org/compare.html?start=64ae15ddd3f3cca7036ab2b2f3a6b130b62af4da&end=39e20f1ae5f13451eb35247808d6a2527cb7d060&stat=faults ) and a 3% regression in [max-rss](https://perf.rust-lang.org/index.html?start=2021-07-01&end=&absolute=false&stat=max-rss) in the ctfe-stress benchmarks. That's most likely happened because it separated allocation from initialization of the vec which defeats the zero-optimization. Currently there's no allocation API that is fallible, zeroing and returns a slice, so this PR introduces one and then uses that to solve the problem. In principle `vec.resize(len, 0)` could be optimized to use `alloc::grow_zeroed` where appropriate but that would require new specializations and new plumbing in `RawVec`.
2021-08-05add Box::try_new_uninit_slice for symmetryThe8472-0/+33
2021-08-05remove cfg gate on `use RawVec` since it is now also used in fallible codeThe8472-1/+0
2021-08-05alloc: Use intra doc links for the reserve functionest31-4/+12
The sentence exists to highlight the existence of a performance footgun of repeated calls of the reserve_exact function.
2021-08-05add Box::try_new_zeroed_slice()The8472-0/+32
Currently there is no API that allows fallible zero-allocation of a Vec. Vec.try_reserve is not appropriate for this job since it doesn't know whether it should zero or arbitrary uninitialized memory is fine. Since Box currently holds most of the zeroing/uninit/slice allocation APIs it's the best place to add yet another entry into this feature matrix.
2021-08-02BTree: merge the complication introduced by #81486 and #86031Stein Somers-56/+56