summary refs log tree commit diff
path: root/library/alloc/src/raw_vec.rs
AgeCommit message (Collapse)AuthorLines
2024-10-06liballoc: introduce String, Vec const-slicingNathan Perry-6/+6
This change `const`-qualifies many methods on Vec and String, notably `as_slice`, `as_str`, `len`. These changes are made behind the unstable feature flag `const_vec_string_slice` with the following tracking issue: https://github.com/rust-lang/rust/issues/129041
2024-09-08add FIXME(const-hack)Ralf Jung-14/+1
2024-08-14apply #[optimize(size)] to #[cold] ones and part of the panick machineryThe 8472-0/+1
2024-08-09Add an optimizer hint for the capacity that with_capacity_in returnsBen Kimock-1/+7
2024-08-09Hoist IS_ZST check out of RawVecInner::from_*_inBen Kimock-6/+15
2024-08-09Polymorphize RawVecBen Kimock-193/+361
2024-07-29Reformat `use` declarations.Nicholas Nethercote-2/+1
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Fix doc nitsJohn Arundel-3/+3
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo", per RFC1574), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits. https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
2024-07-01Avoid MIR bloat in inliningScott McMurray-0/+17
In 126578 we ended up with more binary size increases than expected. This change attempts to avoid inlining large things into small things, to avoid that kind of increase, in cases when top-down inlining will still be able to do that inlining later.
2024-04-12Avoid more NonNull-raw-NonNull roundtrips in VecBen Kimock-0/+11
2024-03-28Rename reserve_for_push to grow_one and fix comment.Cai Bear-3/+3
2024-03-28Remove len argument from RawVec::reserve_for_push because it's always equal ↵Cai Bear-2/+2
to capacity. Also make Vec::insert use reserve_for_push.
2024-03-27Less generic code for Vec allocationsKornel-13/+29
2024-03-10RawVec::into_box: avoid unnecessary intermediate referenceRalf Jung-2/+1
2024-03-09Rollup merge of #120504 - kornelski:try_with_capacity, r=AmanieuGuillaume Boisseau-23/+38
Vec::try_with_capacity Related to #91913 Implements try_with_capacity for `Vec`, `VecDeque`, and `String`. I can follow it up with more collections if desired. `Vec::try_with_capacity()` is functionally equivalent to the current stable: ```rust let mut v = Vec::new(); v.try_reserve_exact(n)? ``` However, `try_reserve` calls non-inlined `finish_grow`, which requires old and new `Layout`, and is designed to reallocate memory. There is benefit to using `try_with_capacity`, besides syntax convenience, because it generates much smaller code at the call site with a direct call to the allocator. There's codegen test included. It's also a very desirable functionality for users of `no_global_oom_handling` (Rust-for-Linux), since it makes a very commonly used function available in that environment (`with_capacity` is used much more frequently than all `(try_)reserve(_exact)`).
2024-03-07Rust is a proper name: rust → RustRalf Jung-1/+1
2024-03-01Move capacity_overflow function to make ui tests change lessKornel-9/+9
Code changes in raw_vec require blessing UI tests every time
2024-03-01try_with_capacity for Vec, VecDeque, StringKornel-0/+9
#91913
2024-03-01try_with_capacity for RawVecKornel-15/+21
2024-02-17Remove unnecessary unit bindinghi-rustin-2/+2
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-02-08Reduce use of NonNull::new_unchecked in library/Ben Kimock-6/+7
2024-01-13libs: use `assert_unchecked` instead of intrinsicjoboet-4/+4
2024-01-11chore: remove unnecessary blank linehi-rustin-1/+0
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-29Italicise "bytes" in the docs of some `Vec` methodsGurinder Singh-2/+2
because on a cursory read it's easy to miss that the limit is in terms of bytes not no. of elements. The italics should help with that.
2023-12-11add comment to RawVec::cap fieldThe 8472-0/+5
2023-12-11add more niches to rawvecThe 8472-15/+36
2023-11-05Auto merge of #117503 - kornelski:hint-try-reserved, r=workingjubileebors-4/+14
Hint optimizer about try-reserved capacity This is #116568, but limited only to the less-common `try_reserve` functions to reduce bloat in debug binaries from debug info, while still addressing the main use-case #116570
2023-11-02Hint optimizer about reserved capacityKornel-4/+14
2023-10-29Increase the reach of panic_immediate_abortBen Kimock-1/+1
2023-10-17Automatically enable cross-crate inlining for small functionsBen Kimock-0/+1
2023-07-13Eliminate ZST allocations in `Box` and `Vec`Amanieu d'Antras-10/+20
2023-04-12remove some unneeded importsKaDiWa-1/+0
2023-01-22simplify layout calculations in rawvecThe 8472-5/+12
2022-09-22Make ZST checks in core/alloc more readableScott McMurray-6/+6
There's a bunch of these checks because of special handing for ZSTs in various unsafe implementations of stuff. This lets them be `T::IS_ZST` instead of `mem::size_of::<T>() == 0` every time, making them both more readable and more terse. *Not* proposed for stabilization at this time. Would be `pub(crate)` except `alloc` wants to use it too. (And while it doesn't matter now, if we ever get something like 85836 making it a const can help codegen be simpler.)
2022-06-29alloc: fix `no_global_oom_handling` warningsMiguel Ojeda-0/+1
Rust 1.62.0 introduced a couple new `unused_imports` warnings in `no_global_oom_handling` builds, making a total of 5 warnings: ```txt warning: unused import: `Unsize` --> library/alloc/src/boxed/thin.rs:6:33 | 6 | use core::marker::{PhantomData, Unsize}; | ^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused import: `from_fn` --> library/alloc/src/string.rs:51:18 | 51 | use core::iter::{from_fn, FusedIterator}; | ^^^^^^^ warning: unused import: `core::ops::Deref` --> library/alloc/src/vec/into_iter.rs:12:5 | 12 | use core::ops::Deref; | ^^^^^^^^^^^^^^^^ warning: associated function `shrink` is never used --> library/alloc/src/raw_vec.rs:424:8 | 424 | fn shrink(&mut self, cap: usize) -> Result<(), TryReserveError> { | ^^^^^^ | = note: `#[warn(dead_code)]` on by default warning: associated function `forget_remaining_elements` is never used --> library/alloc/src/vec/into_iter.rs:126:19 | 126 | pub(crate) fn forget_remaining_elements(&mut self) { | ^^^^^^^^^^^^^^^^^^^^^^^^^ ``` This patch cleans them so that projects compiling `alloc` without infallible allocations do not see the warnings. It also enables the use of `-Dwarnings`. The couple `dead_code` ones may be reverted when some fallible allocation support starts using them. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2022-05-13Remove some unnecessary `rustc_allow_const_fn_unstable` attributes.Nicholas Nethercote-1/+0
2022-04-06formattingSparkyPotato-1/+1
2022-04-06cleanupSparkyPotato-8/+2
2022-04-06fix Vec leak with 0 capacitySparkyPotato-0/+7
2022-02-12Fix typoAlphyr-1/+1
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-02-12Fix `shrink` and `capacity_from_bytes`Benoît du Garreau-2/+3
2022-02-12Fix a layout miscalculation in alloc::RawVecBenoît du Garreau-3/+1
2022-01-19Improve estimation of capacity in Vec::from_iterAngelicosPhosphoros-1/+1
Closes #48994
2021-12-22RawVec: don't recompute capacity after allocating.Nicholas Nethercote-17/+18
Currently it sets the capacity to `ptr.len() / mem::size_of::<T>()` after any buffer allocation/reallocation. This would be useful if allocators ever returned a `NonNull<[u8]>` with a size larger than requested. But this never happens, so it's not useful. Removing this slightly reduces the size of generated LLVM IR, and slightly speeds up the hot path of `RawVec` growth.
2021-11-30Introduce `RawVec::reserve_for_push`.Nicholas Nethercote-0/+8
If `Vec::push`'s capacity check fails it calls `RawVec::reserve`, which then also does a capacity check. This commit introduces `reserve_for_push` which skips the redundant capacity check, for some slight compile time speed-ups. I tried lots of minor variations on this, e.g. different inlining attributes. This was the best one I could find.
2021-11-03Make RawVec private to allocThe8472-57/+4
RawVec was previously exposed for compiler-internal use (libarena specifically) in 1acbb0a9350560d951359cc359361b87992a6f2b Since it is unstable, doc-hidden and has no associated tracking issue it was never meant for public use. And since it is no longer used outside alloc itself it can be made private again. Also remove some functions that are dead due to lack of internal users.
2021-10-10Add #[must_use] to alloc constructorsJohn Kugelman-0/+3
2021-08-28Fix a typo in raw_vecterrarier2111-1/+1
2021-07-24Hide allocator details from TryReserveErrorKornel-10/+10
2021-06-30alloc: `RawVec<T, A>::shrink` can be in `no_global_oom_handling`.Miguel Ojeda-1/+0
Found in https://github.com/Rust-for-Linux/linux/pull/402. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>