about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2021-02-13Auto merge of #81494 - cuviper:btree-node-init, r=Mark-Simulacrumbors-18/+30
Initialize BTree nodes directly in the heap We can avoid any stack-local nodes entirely by using `Box::new_uninit`, and since the nodes are mostly `MaybeUninit` fields, we only need a couple of actual writes before `assume_init`. This should help with the stack overflows in #81444, and may also improve performance in general. r? `@Mark-Simulacrum` cc `@ssomers`
2021-02-13Fix typos in BTreeSet::{first, last} docsTaiki Endo-12/+12
2021-02-13Rollup merge of #82041 - notriddle:shared-from-slice-docs, r=m-ou-seYuki Okushi-0/+98
Add docs for shared_from_slice From impls The advantage of making these docs is mostly in pointing out that these functions all make new allocations and copy/clone/move the source into them. These docs are on the function, and not the `impl` block, to avoid showing the "[+] show undocumented items" button. CC #51430
2021-02-13Rollup merge of #81811 - schteve:fix_vec_retain_doc_test, r=m-ou-seYuki Okushi-3/+4
Fix doc test for Vec::retain(), now passes clippy::eval_order_dependence Doc test for Vec::retain() works correctly but is flagged by clippy::eval_order_dependence. Fix avoids the issue by using an iterator instead of an index.
2021-02-12Update new usage of `assert_len`dylni-2/+2
2021-02-12Rename `Range::ensure_subset_of` to `slice::range`dylni-5/+8
2021-02-12Fix possible soundness issue in `ensure_subset_of`dylni-4/+4
2021-02-12Improve design of `assert_len`dylni-5/+5
2021-02-12Rollup merge of #82023 - MikailBag:boxed-docs-unallow, r=jyn514Dylan DPC-2/+0
Remove unnecessary lint allow attrs on example It seems they are not needed anymore.
2021-02-12Add docs for shared_from_slice From implsMichael Howell-0/+98
The advantage of making these docs is mostly in pointing out that these functions all make new allocations and copy/clone/move the source into them. These docs are on the function, and not the `impl` block, to avoid showing the "[+] show undocumented items" button. CC #51430
2021-02-12Use raw ref macros as in #80886Stein Somers-3/+3
2021-02-12Initialize BTree nodes directly in the heapJosh Stone-18/+30
2021-02-12Remove unnecessary lint allow attrs on exampleMikail Bagishov-2/+0
2021-02-12Auto merge of #81486 - ssomers:btree_separate_drop, r=Mark-Simulacrumbors-65/+106
BTreeMap: disentangle Drop implementation from IntoIter No longer require every `BTreeMap` to dig up its last leaf edge before dying. This speeds up the `clone_` benchmarks by 25% for normal keys and values (far less for huge values). r? `@Mark-Simulacrum`
2021-02-11Auto merge of #81126 - oxalica:retain-early-drop, r=m-ou-sebors-11/+64
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-10BTree: remove outdated traces of coercionsStein Somers-19/+7
2021-02-10Rollup merge of #81687 - WaffleLapkin:split_at_spare, r=KodrAusYuki Okushi-1/+53
Make Vec::split_at_spare_mut public This PR introduces a new method to the public API, under `vec_split_at_spare` feature gate: ```rust impl<T, A: Allocator> impl Vec<T, A> { pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]); } ``` The method returns 2 slices, one slice references the content of the vector, and the other references the remaining spare capacity. The method was previously implemented while adding `Vec::extend_from_within` in #79015, and used to implement `Vec::spare_capacity_mut` (as the later is just a subset of former one). See also previous [discussion in `Vec::spare_capacity_mut` tracking issue](https://github.com/rust-lang/rust/issues/75017#issuecomment-770381335). ## Unresolved questions - [ ] Should we consider changing the name? `split_at_spare_mut` doesn't seem like an intuitive name - [ ] Should we deprecate `Vec::spare_capacity_mut`? Any usecase of `Vec::spare_capacity_mut` can be replaced with `Vec::split_at_spare_mut` (but not vise-versa) r? `@KodrAus`
2021-02-10Rollup merge of #80438 - crlf0710:box_into_inner, r=m-ou-seYuki Okushi-0/+17
Add `Box::into_inner`. This adds a `Box::into_inner` method to the `Box` type. <del>I actually suggest deprecating the compiler magic of `*b` if this gets stablized in the future.</del> r? `@m-ou-se`
2021-02-10update tracking issue for vec_split_at_spareAshley Mannix-1/+1
2021-02-09BTreeMap: disentangle Drop implementation from IntoIterStein Somers-65/+106
2021-02-09BTreeMap: gather and decompose reusable tree fixing functionsStein Somers-146/+176
2021-02-09BTreeMap: fix internal commentsStein Somers-4/+5
2021-02-09BTreeMap: share panicky test code & test panic during clear, cloneStein Somers-183/+303
2021-02-09BTreeMap/BTreeSet: separate off code supporting testsStein Somers-34/+34
2021-02-09Auto merge of #81905 - Dylan-DPC:rollup-mxpz1j7, r=Dylan-DPCbors-2/+12
Rollup of 11 pull requests Successful merges: - #72209 (Add checking for no_mangle to unsafe_code lint) - #80732 (Allow Trait inheritance with cycles on associated types take 2) - #81697 (Add "every" as a doc alias for "all".) - #81826 (Prefer match over combinators to make some Box methods inlineable) - #81834 (Resolve typedef in HashMap lldb pretty-printer only if possible) - #81841 ([rustbuild] Output rustdoc-json-types docs ) - #81849 (Expand the docs for ops::ControlFlow a bit) - #81876 (parser: Fix panic in 'const impl' recovery) - #81882 (:arrow_up: rust-analyzer) - #81888 (Fix pretty printer macro_rules with semicolon.) - #81896 (Remove outdated comment in windows' mutex.rs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-02-09Add `Box::into_inner`.Charles Lew-0/+17
2021-02-09Rollup merge of #81826 - tesuji:inline-box-zeros, r=AmanieuDylan DPC-2/+12
Prefer match over combinators to make some Box methods inlineable Hopefully this patch would make two snippets generated identical code: <https://rust.godbolt.org/z/fjrj4E>.
2021-02-08Auto merge of #81361 - ssomers:btree_drainy_refactor_7, r=Mark-Simulacrumbors-42/+67
BTreeMap: lightly refactor the split_off implementation r? `@Mark-Simulacrum`
2021-02-08Auto merge of #79245 - ssomers:btree_curb_ord_bound, r=dtolnaybors-20/+22
BTree: remove Ord bound where it is absent elsewhere Some btree methods don't really need an Ord bound and don't have one, while some methods that more obviously don't need it, do have one. An example of the former is `iter`, even though it explicitly exposes the work of the Ord implementation (["sorted by key"](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#method.iter) - but I'm not suggesting it should have the Ord bound). An example of the latter is `new`, which doesn't involve any keys whatsoever.
2021-02-07Rollup merge of #81526 - ojeda:btree-use-unwrap_unchecked, r=scottmcmGuillaume Gomez-31/+13
btree: use Option's unwrap_unchecked() Now that https://github.com/rust-lang/rust/issues/81383 is available, start using it.
2021-02-06Fix doc test for Vec::retain(), now passes clippy::eval_order_dependenceSteve Heindel-3/+4
2021-02-06Rollup merge of #81434 - ssomers:btree_drain_filter_doc_update, r=dtolnayJonas Schievink-16/+18
BTree: fix documentation of unstable public members As rightfully requested in #62924 & #70530. r? `@Mark-Simulacrum`
2021-02-06Prefer match intead of combinators to make some Box function inlineableLzu Tao-2/+12
2021-02-06BTreeMap: remove Ord bound where it is absent elsewhereStein Somers-20/+22
2021-02-06BTreeMap: fix documentation of unstable public membersStein Somers-16/+18
2021-02-06Rollup merge of #81610 - ssomers:btree_emphasize_ord_bound, r=dtolnayMara Bos-54/+191
BTreeMap: make Ord bound explicit, compile-test its absence Most `BTreeMap` and `BTreeSet` members are subject to an `Ord` bound but a fair number of methods are not. To better convey and perhaps later tune the `Ord` bound, make it stand out in individual `where` clauses, instead of once far away at the beginning of an `impl` block. This PR does not introduce or remove any bounds. Also adds compilation test cases checking that the bound doesn't creep in unintended on the historically unbounded methods.
2021-02-04Revert "Avoid leaking block expression values"Felix S. Klock II-1/+1
This reverts commit 4fef39113a514bb270f5661a82fdba17d3e41dbb.
2021-02-04Rollup merge of #81727 - m-ou-se:unstabilize-bits, r=Mark-SimulacrumMara Bos-0/+1
Revert stabilizing integer::BITS. We agreed in the libs meeting just now to revert stablization, since the [breakage](https://github.com/rust-lang/rust/issues/81654) is significant throughout the ecosystem, through `lexical-core`. cc https://github.com/rust-lang/rust/issues/76904 Fixes https://github.com/rust-lang/rust/issues/81654
2021-02-03Fixes #80335Yechan Bae-18/+24
2021-02-03Revert stabilizing integer::BITS.Mara Bos-0/+1
2021-02-03Stabilize the Wake traitYoshua Wuyts-7/+59
Co-Authored-By: Ashley Mannix <kodraus@hey.com>
2021-02-03Add note to `Vec::split_at_spare_mut` docs that the method is low-levelWaffle-0/+15
2021-02-03fix typo in library/alloc/src/vec/mod.rsWaffle Lapkin-1/+1
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2021-02-03Make Vec::split_at_spare_mut publicWaffle-1/+38
This commit introduces a new method to the public API, under `vec_split_at_spare` feature gate: ```rust impl<T, A: Allocator> impl Vec<T, A> { pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]); } ``` The method returns 2 slices, one slice references the content of the vector, and the other references the remaining spare capacity. The method was previously implemented while adding `Vec::extend_from_within`, and used to implement `Vec::spare_capacity_mut` (as the later is just a subset of former one).
2021-02-02Rollup merge of #81588 - xfix:delete-doc-alias, r=Mark-SimulacrumJack Huey-0/+2
Add doc aliases for "delete" This patch adds doc aliases for "delete". The added aliases are supposed to reference usages `delete` in other programming languages. - `HashMap::remove`, `BTreeMap::remove` -> `Map#delete` and `delete` keyword in JavaScript. - `HashSet::remove`, `BTreeSet::remove` -> `Set#delete` in JavaScript. - `mem::drop` -> `delete` keyword in C++. - `fs::remove_file`, `fs::remove_dir`, `fs::remove_dir_all`-> `File#delete` in Java, `File#delete` and `Dir#delete` in Ruby. Before this change, searching for "delete" in documentation returned no results.
2021-02-02BTreeMap: make Ord bound explicit, compile-test its absenceStein Somers-54/+191
2021-02-02Auto merge of #79015 - WaffleLapkin:vec_append_from_within, r=KodrAusbors-4/+110
add `Vec::extend_from_within` method under `vec_extend_from_within` feature gate Implement <https://github.com/rust-lang/rfcs/pull/2714> ### tl;dr This PR adds a `extend_from_within` method to `Vec` which allows copying elements from a range to the end: ```rust #![feature(vec_extend_from_within)] let mut vec = vec![0, 1, 2, 3, 4]; vec.extend_from_within(2..); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4]); vec.extend_from_within(..2); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1]); vec.extend_from_within(4..8); assert_eq!(vec, [0, 1, 2, 3, 4, 2, 3, 4, 0, 1, 4, 2, 3, 4]); ``` ### Implementation notes Originally I've copied `@Shnatsel's` [implementation](https://github.com/WanzenBug/rle-decode-helper/blob/690742a0de158d391b7bde1a0c71cccfdad33ab3/src/lib.rs#L74) with some minor changes to support other ranges: ```rust pub fn append_from_within<R>(&mut self, src: R) where T: Copy, R: RangeBounds<usize>, { let len = self.len(); let Range { start, end } = src.assert_len(len);; let count = end - start; self.reserve(count); unsafe { // This is safe because `reserve()` above succeeded, // so `self.len() + count` did not overflow usize ptr::copy_nonoverlapping( self.get_unchecked(src.start), self.as_mut_ptr().add(len), count, ); self.set_len(len + count); } } ``` But then I've realized that this duplicates most of the code from (private) `Vec::append_elements`, so I've used it instead. Then I've applied `@KodrAus` suggestions from https://github.com/rust-lang/rust/pull/79015#issuecomment-727200852.
2021-02-02update tracking issue for vec_extend_from_withinAshley Mannix-1/+1
2021-01-31add `Vec::extend_from_within` methodWaffle-4/+110
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-31Rollup merge of #81590 - KodrAus:stabilize/int_bits_const, r=m-ou-seJonas Schievink-1/+0
Stabilize int_bits_const Closes #76904 The FCP to stabilize the `int_bits_const` feature completed on the tracking issue.