summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2020-03-10Rollup merge of #69877 - CAD97:patch-1, r=dtolnayMazdak Farrokhzad-1/+1
Vec::new is const stable in 1.39 not 1.32 Changelog: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1390-2019-11-07 This really surprised me when a MSRV check for 1.35 failed with `Vec::new is not yet stable as a const fn` and the docs said that it was const stabilized in 1.32.
2020-03-10Rollup merge of #69861 - Dylnuge:dylnuge/locale-doc, r=Mark-SimulacrumMazdak Farrokhzad-0/+15
Add note about localization to std::fmt docs Closes #69681
2020-03-10Rollup merge of #69799 - TimDiekmann:zst, r=AmanieuMazdak Farrokhzad-27/+47
Allow ZSTs in `AllocRef` Allows ZSTs in all `AllocRef` methods. The implementation of `AllocRef` for `Global` and `System` were adjusted to reflect those changes. This is the second item on the roadmap to support ZSTs in `AllocRef`: https://github.com/rust-lang/wg-allocators/issues/38#issuecomment-595861542 After this has landed, I will adapt `RawVec`, but since this will be a pretty big overhaul, it makes sense to do a different PR for it. ~~Requires #69794 to land first~~ r? @Amanieu
2020-03-09Vec::new is const tstable in 1.39 not 1.32Christopher Durham-1/+1
2020-03-09Add note about localization to std::fmt docsDylan Nugent-0/+15
2020-03-08Rollup merge of #69668 - ssomers:btreemap_even_more_comments, r=Mark-SimulacrumMazdak Farrokhzad-14/+19
More documentation and simplification of BTreeMap's internals Salvage the documentation and simplification from #67980, without changing the type locked down by debuginfo. r? @rkruppe
2020-03-08Rollup merge of #69776 - ssomers:fix69769, r=Mark-SimulacrumMazdak Farrokhzad-2/+35
Fix & test leak of some BTreeMap nodes on panic during `into_iter` Fixes #69769
2020-03-08Allow ZSTs in `AllocRef`Tim Diekmann-27/+47
2020-03-07Rollup merge of #69773 - matthiaskrgr:typos, r=petrochenkovMazdak Farrokhzad-6/+6
fix various typos
2020-03-07Rollup merge of #69765 - RalfJung:miri-test, r=LukasKalbertodtMazdak Farrokhzad-2/+2
reduce test size for Miri The larger sizes take quite a while, and there is probably little point in repeating this quite so often.
2020-03-06Don't redundantly repeat field names (clippy::redundant_field_names)Matthias Krüger-2/+2
2020-03-06fix various typosMatthias Krüger-6/+6
2020-03-06Fix & test leak of some BTreeMap nodes on panic during `into_iter`Stein Somers-2/+35
2020-03-05reduce test size for MiriRalf Jung-2/+2
2020-03-05Fixed a typoTrolledWoods-1/+1
"vector" was used instead of "string"
2020-03-04Documentation and slight simplification of BTreeMap's internalsStein Somers-14/+19
2020-03-03Rollup merge of #69650 - matthiaskrgr:clnp, r=varkorDylan DPC-1/+1
cleanup more iterator usages (and other things) * Improve weird formatting by moving comment inside else-code block. * Use .any(x) instead of .find(x).is_some() on iterators. * Use .nth(x) instead of .skip(x).next() on iterators. * Simplify conditions like x + 1 <= y to x < y * Use let instead of match to get value of enum with single variant.
2020-03-03Rollup merge of #69609 - TimDiekmann:excess, r=AmanieuYuki Okushi-22/+27
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-03Simplify conditions like x + 1 <= y to x < yMatthias Krüger-1/+1
2020-03-03Remove `usable_size` APIsTim Diekmann-22/+27
2020-03-01Rollup merge of #69569 - matthiaskrgr:nonminimal_bool, r=mark-SimulacrumDylan DPC-2/+2
simplify boolean expressions
2020-03-01Rollup merge of #69568 - JOE1994:patch-2, r=Dylan-DPCDylan DPC-2/+3
Clarify explanation of Vec<T> 'fn resize' 1. Clarified on what should implement `Clone` trait. 2. Minor grammar fix: to be able clone => to be able **to** clone
2020-02-29clarify alignment requirements in Vec::from_raw_partsRalf Jung-1/+5
2020-02-29simplify boolean expressionsMatthias Krüger-2/+2
2020-02-29Remove trailing whitespaceYoungsuk Kim-1/+1
Removed trailing whitespace which caused to fail pretty-check
2020-02-29Update src/liballoc/vec.rs Youngsuk Kim-1/+1
Following suggestion from @jonas-schievink Co-Authored-By: Jonas Schievink <jonasschievink@gmail.com>
2020-02-28Clarify explanation of 'fn resize'Youngsuk Kim-2/+3
1. Clarified on what should implement 'Clone' trait. 2. Minor grammar fix: to be able clone => to be able to clone
2020-02-28Rollup merge of #69538 - JohnTitor:boxed-slice-try-from, r=CentrilMazdak Farrokhzad-3/+3
Stabilize `boxed_slice_try_from` Closes #69202
2020-02-28Auto merge of #68827 - ssomers:btree_navigation_revisited, r=Mark-Simulacrumbors-166/+233
BTreeMap navigation done safer & faster It turns out that there was a faster way to do the tree navigation code bundled in #67073, by moving from edge to KV and from KV to next edge separately. It extracts most of the code as safe functions, and contains the duplication of handles within the short wrapper functions. This somehow hits a sweet spot in the compiler because it reports boosts all over the board: ``` >cargo benchcmp pre3.txt posz4.txt --threshold 5 name pre3.txt ns/iter posz4.txt ns/iter diff ns/iter diff % speedup btree::map::first_and_last_0 40 37 -3 -7.50% x 1.08 btree::map::first_and_last_100 58 44 -14 -24.14% x 1.32 btree::map::iter_1000 8,920 3,419 -5,501 -61.67% x 2.61 btree::map::iter_100000 1,069,290 411,615 -657,675 -61.51% x 2.60 btree::map::iter_20 169 58 -111 -65.68% x 2.91 btree::map::iter_mut_1000 8,701 3,303 -5,398 -62.04% x 2.63 btree::map::iter_mut_100000 1,034,560 405,975 -628,585 -60.76% x 2.55 btree::map::iter_mut_20 165 58 -107 -64.85% x 2.84 btree::set::clone_100 1,831 1,562 -269 -14.69% x 1.17 btree::set::clone_100_and_clear 1,831 1,565 -266 -14.53% x 1.17 btree::set::clone_100_and_into_iter 1,917 1,541 -376 -19.61% x 1.24 btree::set::clone_100_and_pop_all 2,609 2,441 -168 -6.44% x 1.07 btree::set::clone_100_and_remove_all 4,598 3,927 -671 -14.59% x 1.17 btree::set::clone_100_and_remove_half 2,765 2,551 -214 -7.74% x 1.08 btree::set::clone_10k 191,610 164,616 -26,994 -14.09% x 1.16 btree::set::clone_10k_and_clear 192,003 164,616 -27,387 -14.26% x 1.17 btree::set::clone_10k_and_into_iter 200,037 163,010 -37,027 -18.51% x 1.23 btree::set::clone_10k_and_pop_all 267,023 250,913 -16,110 -6.03% x 1.06 btree::set::clone_10k_and_remove_all 536,230 464,100 -72,130 -13.45% x 1.16 btree::set::clone_10k_and_remove_half 453,350 430,545 -22,805 -5.03% x 1.05 btree::set::difference_random_100_vs_100 1,787 801 -986 -55.18% x 2.23 btree::set::difference_random_100_vs_10k 2,978 2,696 -282 -9.47% x 1.10 btree::set::difference_random_10k_vs_100 111,075 54,734 -56,341 -50.72% x 2.03 btree::set::difference_random_10k_vs_10k 246,380 175,980 -70,400 -28.57% x 1.40 btree::set::difference_staggered_100_vs_100 1,789 951 -838 -46.84% x 1.88 btree::set::difference_staggered_100_vs_10k 2,798 2,606 -192 -6.86% x 1.07 btree::set::difference_staggered_10k_vs_10k 176,452 97,401 -79,051 -44.80% x 1.81 btree::set::intersection_100_neg_vs_10k_pos 34 32 -2 -5.88% x 1.06 btree::set::intersection_100_pos_vs_100_neg 30 27 -3 -10.00% x 1.11 btree::set::intersection_random_100_vs_100 1,537 613 -924 -60.12% x 2.51 btree::set::intersection_random_100_vs_10k 2,793 2,649 -144 -5.16% x 1.05 btree::set::intersection_random_10k_vs_10k 222,127 147,166 -74,961 -33.75% x 1.51 btree::set::intersection_staggered_100_vs_100 1,447 622 -825 -57.01% x 2.33 btree::set::intersection_staggered_100_vs_10k 2,606 2,382 -224 -8.60% x 1.09 btree::set::intersection_staggered_10k_vs_10k 143,620 58,790 -84,830 -59.07% x 2.44 btree::set::is_subset_100_vs_100 1,349 488 -861 -63.83% x 2.76 btree::set::is_subset_100_vs_10k 1,720 1,428 -292 -16.98% x 1.20 btree::set::is_subset_10k_vs_10k 135,984 48,527 -87,457 -64.31% x 2.80 ``` The `first_and_last` ones are noise (they don't do iteration), the others seem genuine. As always, approved by Miri. Also, a separate commit with some more benchmarks of mutable behaviour (which also benefit). r? @cuviper
2020-02-28Stabilize `boxed_slice_try_from`Yuki Okushi-3/+3
2020-02-28Make implementation of navigation simpler, safer and fasterStein Somers-150/+148
2020-02-28Fix and test implementation of BTreeMap's first_entry, last_entry, ↵Stein Somers-21/+35
pop_first, pop_last
2020-02-26Auto merge of #67290 - jonas-schievink:leak-audit, r=KodrAusbors-128/+497
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
2020-02-22Auto merge of #67330 - golddranks:split_inclusive, r=kodrausbors-0/+124
Implement split_inclusive for slice and str # Overview * Implement `split_inclusive` for `slice` and `str` and `split_inclusive_mut` for `slice` * `split_inclusive` is a substring/subslice splitting iterator that includes the matched part in the iterated substrings as a terminator. * EDIT: The behaviour has now changed, as per @KodrAus 's input, to the same semantics with the `split_terminator` function. I updated the examples below. * Two examples below: ```Rust let data = "\nMäry häd ä little lämb\nLittle lämb\n"; let split: Vec<&str> = data.split_inclusive('\n').collect(); assert_eq!(split, ["\n", "Märy häd ä little lämb\n", "Little lämb\n"]); ``` ```Rust let uppercase_separated = "SheePSharKTurtlECaT"; let mut first_char = true; let split: Vec<&str> = uppercase_separated.split_inclusive(|c: char| { let split = !first_char && c.is_uppercase(); first_char = split; split }).collect(); assert_eq!(split, ["SheeP", "SharK", "TurtlE", "CaT"]); ``` # Justification for the API * I was surprised to find that stdlib currently only has splitting iterators that leave out the matched part. In my experience, wanting to leave a substring terminator as a part of the substring is a pretty common usecase. * This API is strictly more expressive than the standard `split` API: it's easy to get the behaviour of `split` by mapping a subslicing operation that drops the terminator. On the other hand it's impossible to derive this behaviour from `split` without using hacky and brittle `unsafe` code. The normal way to achieve this functionality would be implementing the iterator yourself. * Especially when dealing with mutable slices, the only way currently is to use `split_at_mut`. This API provides an ergonomic alternative that plays to the strengths of the iterating capabilities of Rust. (Using `split_at_mut` iteratively used to be a real pain before NLL, fortunately the situation is a bit better now.) # Discussion items * <s>Does it make sense to mimic `split_terminator` in that the final empty slice would be left off in case of the string/slice ending with a terminator? It might do, as this use case is naturally geared towards considering the matching part as a terminator instead of a separator.</s> * EDIT: The behaviour was changed to mimic `split_terminator`. * Does it make sense to have `split_inclusive_mut` for `&mut str`?
2020-02-20Rollup merge of #68705 - BijanT:ll_remove, r=Mark-SimulacrumDylan DPC-0/+46
Add LinkedList::remove() LinkedList::remove() removes the element at the specified index and returns it. I added this because I think having a remove function would be useful to have, and similar functions are in other containers, like Vec and HashMap. I'm not sure if adding a feature like this requires an RFC or not, so I'm sorry if this PR is premature.
2020-02-19Change FromStr for String to use Infallible directlyPeter Todd-11/+4
Fixes the confusing documentation on `ParseError` by making it irrelevant.
2020-02-19Add LinkedList::remove()Bijan Tabatabai-0/+46
LinkedList::remove() removes the element at the specified index and returns it. Signed-off-by: Bijan Tabatabai <bijan311@yahoo.com>
2020-02-16Lighten tests, in particular for Miri, yet test and explain moreStein Somers-20/+32
2020-02-16Fix comments outdated during #66648Stein Somers-5/+4
2020-02-12Rollup merge of #69058 - TimDiekmann:box, r=AmanieuYuki Okushi-21/+28
Preparation for allocator aware `Box` This cleans up the `Box` code a bit, and uses `Box::from_raw(ptr)` instead of `Box(ptr)`. Additionally, `box_free` and `exchange_malloc` now uses the `AllocRef` trait and a comment was added on how `box_free` is tied to `Box`. This a preparation for an upcoming PR, which makes `Box` aware of an allocator. r? @Amanieu
2020-02-11Preparation for allocator aware `Box`Tim Diekmann-21/+28
2020-02-10Remove common usage pattern from `AllocRef`Tim Diekmann-6/+7
2020-02-09Rollup merge of #68742 - tspiteri:string-as-mut, r=sfacklerJonas Schievink-0/+8
implement AsMut<str> for String Closes #68741.
2020-02-09Rollup merge of #68738 - kennytm:derive-clone-eq-for-fromutf8error, r=sfacklerJonas Schievink-1/+5
Derive Clone + Eq for std::string::FromUtf8Error Implement `Clone` and `Eq` for `std::string::FromUtf8Error`. Both the inner `Vec<u8>` and `std::str::Utf8Error` are also `Clone + Eq`, so I don't see why we shouldn't derive them on `FromUtf8Error` as well. (impl are insta-stable, requiring FCP from T-libs.)
2020-02-09Don't return empty slice on last iteration with matched terminator. Test ↵Pyry Kontio-9/+94
reverse iteration.
2020-02-09Implement split_inclusive for slice and str, an splitting iterator that ↵Pyry Kontio-0/+39
includes the matched part in the iterated substrings as a terminator.
2020-02-09Rollup merge of #68834 - ssomers:btree_first_last_fix68829, r=KodrAusDylan DPC-21/+35
Fix and test implementation of BTreeMap's first/last_entry, pop_first/last Properly implement and test `first_entry` & `last_entry` to fix problem report #68829
2020-02-08Refine and extend benchmarks of mutable BTreeSet methodsStein Somers-16/+85
2020-02-07Auto merge of #68499 - ssomers:btree_search_tidying, r=Mark-Simulacrumbors-42/+101
BtreeMap range_search spruced up #39457 created a lower level entry point for `range_search` to operate on, but it's really not hard to move it up a level of abstraction, making it somewhat shorter and reusing existing unsafe code (`new_edge` is unsafe although it is currently not tagged as such). Benchmark added. Comparison says there's no real difference: ``` >cargo benchcmp old3.txt new3.txt --threshold 5 name old3.txt ns/iter new3.txt ns/iter diff ns/iter diff % speedup btree::map::find_seq_100 19 21 2 10.53% x 0.90 btree::map::range_excluded_unbounded 3,117 2,838 -279 -8.95% x 1.10 btree::map::range_included_unbounded 1,768 1,871 103 5.83% x 0.94 btree::set::intersection_10k_neg_vs_10k_pos 35 37 2 5.71% x 0.95 btree::set::intersection_staggered_100_vs_10k 2,488 2,314 -174 -6.99% x 1.08 btree::set::is_subset_10k_vs_100 3 2 -1 -33.33% x 1.50 ``` r? @Mark-Simulacrum
2020-02-07Lift range_search up one level of abstractionStein Somers-42/+45