about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2020-06-18Add specialization of `ToString for char`Lzu Tao-0/+8
2020-06-17Reduce pointer casts in Box::into_boxed_sliceJosh Stone-1/+1
We only need to cast the pointer once to change `Box<T>` to an array `Box<[T; 1]>`, then we can let unsized coercion return `Box<[T]>`.
2020-06-15Rollup merge of #72584 - CAD97:stabilize-58957, r=dtolnayRalf Jung-2/+8
Stabilize vec::Drain::as_slice and add `AsRef<[T]> for Drain<'_, T>`. Tracking issue: #58957. Does not stabilize `slice::IterMut::as_slice` yet. cc @cuviper This PR proposes stabilizing just the `vec::Drain::as_slice` part of that tracking issue. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
2020-06-12Rollup merge of #72906 - lzutao:migrate-numeric-assoc-consts, r=dtolnayDylan DPC-17/+17
Migrate to numeric associated consts The deprecation PR is #72885 cc #68490 cc rust-lang/rfcs#2700
2020-06-10Migrate to numeric associated constsLzu Tao-17/+17
2020-06-09Rename some identifiers in `RawVec` and `libarena`.Nicholas Nethercote-53/+36
- Use `len` more consistently for the number of elements in a vector, because that's the usual name. - Use `additional` more consistently for the number of elements we want to add, because that's what `Vec::reserve()` uses. - Use `cap` consistently rather than `capacity`. - Plus a few other tweaks. This increases consistency and conciseness.
2020-06-09Remove `RawVec::reserve_in_place`.Nicholas Nethercote-39/+6
Also remove a now-unnecessary `placement` argument.
2020-06-08Rollup merge of #72811 - pickfire:liballoc-impl, r=AmanieuRalf Jung-42/+40
Liballoc impl Mainly code rearrangements
2020-06-08Rollup merge of #72583 - CAD97:vec-iter-asref-slice, r=dtolnayRalf Jung-0/+7
impl AsRef<[T]> for vec::IntoIter<T> Adds `impl<T> AsRef<[T]> for vec::IntoIter<T>`. This mirrors the same trait impl for [`slice::Iter`](https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html). Both types already offer `fn as_slice(&self) -> &[T]`, this just adds the trait impl for `vec::IntoIter`. If/when `fn as_slice(&self) -> &[T]` stabilizes for `vec::Drain` and `slice::IterMut`, they should get `AsRef<[T]>` impls as well. As thus, tangentially related to #58957. My ultimate goal here: being able to use `for<T, I: Iterator<Item=T> + AsRef<[T]>> I` to refer to `vec::IntoIter`, `vec::Drain`, and eventually `array::IntoIter`, as an approximation of the set of by-value iterators that can be "previewed" as by-ref iterators. (Actually expressing that as a trait requires GAT.)
2020-06-06Elide type on liballoc vecIvan Tham-1/+1
2020-06-05Auto merge of #73025 - Dylan-DPC:rollup-a1uzj5u, r=Dylan-DPCbors-1/+1
Rollup of 5 pull requests Successful merges: - #72260 (Spell out `Self` in async function return) - #72996 (Remove unsused `NodeId` related APIs in hir map) - #73010 (Update RELEASES.md) - #73017 (Use assert_eq for liballoc test) - #73019 (add test for #72960) Failed merges: r? @ghost
2020-06-05Auto merge of #72957 - Mark-Simulacrum:bootstrap-bump, r=sfacklerbors-24/+5
Bump bootstrap compiler to 1.45 Pretty standard update.
2020-06-05Use assert_eq for liballoc testIvan Tham-1/+1
2020-06-05Add more assert to Vec with_capacity docsIvan Tham-0/+3
Show assertion on len too to show them how adding new items will affect both the length and capacity, before and after.
2020-06-03Bump to 1.46Mark Rousskov-24/+5
2020-06-03Add assert to Vec with_capacity docsIvan Tham-0/+2
2020-06-01Mention that BTreeMap::new() doesn't allocateTrolledWoods-0/+2
I think it would be nice to mention this, so you don't have to dig through the src to look at the definition of new().
2020-05-31Merge raw_vec into_box with previous impl<T, Global>Ivan Tham-26/+24
There are two separate `impl<T, Global>` which no special reason, it would be better to merge both of them.
2020-05-31Rearrange impl blocks with Deref as firstIvan Tham-16/+16
The other blocks depends on Deref to make it easier for readers when reimplementing or reading the implementations.
2020-05-30Rollup merge of #72499 - mendess:master, r=dtolnayRalf Jung-0/+41
Override Box::<[T]>::clone_from Avoid dropping and reallocating when cloning to an existing box if the lengths are the same. It would be nice if this could also be specialized for `Copy` but I don't know how that works since it's not on stable. Will gladly look into it if it's deemed as a good idea. This is my first PR with code, hope I did everything right :smile:
2020-05-30Rollup merge of #72162 - cuviper:extend_one, r=Mark-SimulacrumYuki Okushi-0/+126
Add Extend::{extend_one,extend_reserve} This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
2020-05-29Add Extend::{extend_one,extend_reserve}Josh Stone-0/+126
This adds new optional methods on `Extend`: `extend_one` add a single element to the collection, and `extend_reserve` pre-allocates space for the predicted number of incoming elements. These are used in `Iterator` for `partition` and `unzip` as they shuffle elements one-at-a-time into their respective collections.
2020-05-29Auto merge of #72756 - RalfJung:rollup-tbjmtx2, r=RalfJungbors-0/+19
Rollup of 9 pull requests Successful merges: - #67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - #71095 (impl From<[T; N]> for Box<[T]>) - #71500 (Make pointer offset methods/intrinsics const) - #71804 (linker: Support `-static-pie` and `-static -shared`) - #71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - #72103 (borrowck `DefId` -> `LocalDefId`) - #72407 (Various minor improvements to Ipv6Addr::Display) - #72413 (impl Step for char (make Range*<char> iterable)) - #72439 (NVPTX support for new asm!) Failed merges: r? @ghost
2020-05-29Rollup merge of #71095 - pickfire:box-from-array, r=dtolnayRalf Jung-0/+19
impl From<[T; N]> for Box<[T]> Based on https://github.com/rust-lang/rust/pull/68692
2020-05-29Rollup merge of #72701 - pickfire:patch-1, r=Mark-SimulacrumDylan DPC-1/+1
Fix grammar in liballoc raw_vec
2020-05-29Remove flaky test and document the other's flakinessmendess-8/+5
2020-05-29Rollup merge of #72288 - vorner:stabilize-weak-into-raw, r=dtolnayYuki Okushi-24/+8
Stabilization of weak-into-raw Closes #60728. There are also two removals of `#![feature(weak_into_raw)]` in the `src/tools/miri` submodule. How should I synchronize the changes with there? * I can ignore it for now and once this gets merged, update the tool, send a pull request to that one and then reference the changes to rustc. * I could try submitting the changes to miri first, but then the build would fail there, because the attribute would still be needed. I think the first one is the correct one, extrapolating from the contributing guidelines (even though they speak about breaking the tools and this should not break it, as extra feature should not hurt).
2020-05-29Fix grammar in liballoc raw_vecIvan Tham-1/+1
2020-05-27added .collect() into String from Box<str> with fake feature/stability ↵djugei-0/+16
annotation
2020-05-27Rollup merge of #72533 - Diggsey:db-fix-arc-ub2, r=dtolnayDylan DPC-9/+26
Resolve UB in Arc/Weak interaction (2) Use raw pointers to avoid making any assertions about the data field. Follow up from #72479, see that PR for more detail on the motivation. @RalfJung I was able to avoid a lot of the changes to `Weak`, by making a helper type (`WeakInner`) - because of auto-deref and because the fields have the same name, the rest of the code continues to compile.
2020-05-25stabilize vec_drain_as_sliceCAD97-2/+8
2020-05-25impl AsRef<[T]> for vec::IntoIter<T>CAD97-0/+7
2020-05-25Fix UB in ArcDiggory Blake-9/+26
Use raw pointers to avoid making any assertions about the data field.
2020-05-23Add testsmendess-0/+36
2020-05-23Override Box::<[T]>::clone_frommendess-0/+8
2020-05-20impl From<[T; N]> for Box<[T]>Ivan Tham-0/+19
Based on https://github.com/rust-lang/rust/pull/68692
2020-05-20Adjust the zero check in `RawVec::grow`.Nicholas Nethercote-4/+3
This was supposed to land as part of #72227. (I wish `git push` would abort when you have uncommited changes.)
2020-05-19Auto merge of #72227 - nnethercote:tiny-vecs-are-dumb, r=Amanieubors-5/+141
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/+103
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-5/+141
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-05-17Auto merge of #72204 - RalfJung:abort, r=Mark-Simulacrumbors-0/+9
make abort intrinsic safe, and correct its documentation Turns out `std::process::abort` is not the same as the intrinsic, the comment was just wrong. Quoting from the unix implementation: ``` // On Unix-like platforms, libc::abort will unregister signal handlers // including the SIGABRT handler, preventing the abort from being blocked, and // fclose streams, with the side effect of flushing them so libc buffered // output will be printed. Additionally the shell will generally print a more // understandable error message like "Abort trap" rather than "Illegal // instruction" that intrinsics::abort would cause, as intrinsics::abort is // implemented as an illegal instruction. ```
2020-05-17make abort intrinsic safe, and correct its documentationRalf Jung-0/+9
2020-05-17Stabilization of weak-into-rawMichal 'vorner' Vaner-24/+8
Stabilizes #60728.
2020-05-14Auto merge of #71321 - matthewjasper:alloc-min-spec, r=sfacklerbors-120/+42
Use min_specialization in liballoc - Remove a type parameter from `[A]RcFromIter`. - Remove an implementation of `[A]RcFromIter` that didn't actually specialize anything. - Remove unused implementation of `IsZero` for `Option<&mut T>`. - Change specializations of `[A]RcEqIdent` to use a marker trait version of `Eq`. - Remove `BTreeClone`. I couldn't find a way to make this work with `min_specialization`. - Add `rustc_unsafe_specialization_marker` to `Copy` and `TrustedLen`. After this only libcore is the only standard library crate using `feature(specialization)`. cc #31844
2020-05-14Fix Arc::decr_strong_count doc testTomasz Miąsko-3/+5
2020-05-13Auto merge of #72013 - nnethercote:make-RawVec-grow-mostly-non-generic, ↵bors-149/+95
r=Amanieu Make `RawVec::grow` mostly non-generic. `cargo-llvm-lines` shows that, in various benchmarks, `RawVec::grow` is instantiated 10s or 100s of times and accounts for 1-8% of lines of generated LLVM IR. This commit moves most of `RawVec::grow` into a separate function that isn't parameterized by `T`, which means it doesn't need to be instantiated many times. This reduces compile time significantly. r? @ghost
2020-05-12Rollup merge of #71737 - RalfJung:miri-test-threads, r=shepmasterDylan DPC-9/+10
Miri: run liballoc tests with threads Miri now supports threads, so we can run these tests. :)
2020-05-12Split `RawVec::grow` up.Nicholas Nethercote-50/+79
The amortized case is much more common than the exact case, and it is typically instantiated many times. Also, we can put a chunk of the code into a function that isn't generic over T, which reduces the amount of LLVM IR generated quite a lot, improving compile times.
2020-05-12Remove `RawVec::double`.Nicholas Nethercote-88/+23
It's only used once, for `VecDeque`, and can easily be replaced by something else. The commit changes `grow_if_necessary` to `grow` to avoid some small regressions caused by changed inlining. The commit also removes `Strategy::Double`, and streamlines the remaining variants of `Strategy`. It's a compile time win on some benchmarks because the many instantations of `RawVec::grow` are a little smaller.
2020-05-12Remove `RawVec::double_in_place`.Nicholas Nethercote-18/+0
It's unused.