about summary refs log tree commit diff
path: root/library/alloc/src/vec/mod.rs
AgeCommit message (Collapse)AuthorLines
2021-09-30Add truncate note to Vec::resizeOwen Gage-0/+1
2021-09-28Additional docs about Vec::leak behaviorMatt Brubeck-2/+5
2021-09-28Avoid allocations and copying in Vec::leakMatt Brubeck-1/+2
Don't shrink the Vec (by calling into_boxed_slice) before leaking it.
2021-09-26Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakisbors-0/+1
2229: Mark insignificant dtor in stdlib I looked at all public [stdlib Drop implementations](https://doc.rust-lang.org/stable/std/ops/trait.Drop.html#implementors) and categorized them into Insigificant/Maybe/Significant Drop. Reasons are noted here: https://docs.google.com/spreadsheets/d/19edb9r5lo2UqMrCOVjV0fwcSdS-R7qvKNL76q7tO8VA/edit#gid=1838773501 One thing missing from this PR is tagging HashMap as insigificant destructor as that needs some discussion. r? `@Mark-Simulacrum` cc `@nikomatsakis`
2021-09-25Rollup merge of #89216 - r00ster91:bigo, r=dtolnayManish Goregaokar-3/+3
Consistent big O notation This makes the big O time complexity notation in places with markdown support more consistent. Inspired by #89210
2021-09-25Auto merge of #88343 - steffahn:fix_code_spacing, r=jyn514bors-7/+9
Fix spacing of links in inline code. Similar to #80733, but the focus is different. This PR eliminates all occurrences of pieced-together inline code blocks like [`Box`]`<`[`Option`]`<T>>` and replaces them with good-looking ones (using HTML-syntax), like <code>[Box]<[Option]\<T>></code>. As far as I can tell, I should’ve found all of these in the standard library (regex search with `` r"`\]`|`\[`" ``) \[except for in `core::convert` where I’ve noticed other things in the docs that I want to fix in a separate PR]. In particular, unlike #80733, I’ve added almost no new instance of inline code that’s broken up into multiple links (or some link and some link-free part). I also added tooltips (the stuff in quotes for the markdown link listings) in places that caught my eye, but that’s by no means systematic, just opportunistic. [Box]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [Option]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" [`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" Context: I got annoyed by repeatedly running into new misformatted inline code while reading the standard library docs. I know that once issue #83997 (and/or related ones) are resolved, these changes become somewhat obsolete, but I fail to notice much progress on that end right now. r? `@jyn514`
2021-09-25Apply 16 commits (squashed)Frank Steffahn-7/+9
---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::fmt ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::{rc, sync} ---------- Fix spacing for links inside code blocks, and improve link tooltips in alloc::string ---------- Fix spacing for links inside code blocks in alloc::vec ---------- Fix spacing for links inside code blocks in core::option ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in core::result ---------- Fix spacing for links inside code blocks in core::{iter::{self, iterator}, stream::stream, poll} ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{fs, path} ---------- Fix spacing for links inside code blocks in std::{collections, time} ---------- Fix spacing for links inside code blocks in and make formatting of `&str`-like types consistent in std::ffi::{c_str, os_str} ---------- Fix spacing for links inside code blocks, and improve link tooltips in std::ffi ---------- Fix spacing for links inside code blocks, and improve a few link tooltips in std::{io::{self, buffered::{bufreader, bufwriter}, cursor, util}, net::{self, addr}} ---------- Fix typo in link to `into` for `OsString` docs ---------- Remove tooltips that will probably become redundant in the future ---------- Apply suggestions from code review Replacing `…std/primitive.reference.html` paths with just `reference` Co-authored-by: Joshua Nelson <github@jyn.dev> ---------- Also replace `…std/primitive.reference.html` paths with just `reference` in `core::pin`
2021-09-24consistent big O notationr00ster91-3/+3
2021-09-22PR fixupAman Arora-1/+1
2021-09-212229: Annotate stdlib with insignficant dtorsAman Arora-0/+1
2021-09-17Fix missing `no_global_oom_handling` cfg-gatingGary Guo-0/+1
2021-09-17Optimize unnecessary check in Vec::retainTennyZhuang-3/+24
Co-authored-by: oxalica <oxalicc@pm.me>
2021-08-26Add missing # Panics section to `Vec` methodSebastian Widua-1/+6
namely `Vec::extend_from_within`
2021-08-17Constified `Default` implementationsDeadbeef-1/+2
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-12Add missing cfg attributeBenoît du Garreau-0/+3
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-2/+1
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-1/+1
2021-08-05alloc: Use intra doc links for the reserve functionest31-2/+6
The sentence exists to highlight the existence of a performance footgun of repeated calls of the reserve_exact function.
2021-08-02Rollup merge of #87644 - Flying-Toast:vec-remove-note, r=the8472Yuki Okushi-0/+6
Recommend `swap_remove` in `Vec::remove` docs I was able to increase the performance (by 20%!) of my project by changing a `Vec::remove` call to `Vec::swap_remove` in a hot function. I think we should explicitly put a note in the Vec::remove docs to guide people in the right direction so they don't make a similar oversight.
2021-07-31Auto merge of #87488 - kornelski:track-remove, r=dtolnaybors-0/+2
Track caller of Vec::remove() `vec.remove(invalid)` doesn't print a helpful source position: > thread 'main' panicked at 'removal index (is 99) should be < len (is 1)', **library/alloc/src/vec/mod.rs:1379:13**
2021-07-30Recommend `swap_remove` in `Vec::remove` docsFlying-Toast-0/+6
2021-07-29Fix may not to appropriate might not or must notAli Malik-1/+1
2021-07-26Track caller of Vec::remove()Kornel-0/+2
2021-07-24Auto merge of #84111 - bstrie:hashfrom, r=joshtriplettbors-4/+5
Stabilize `impl From<[(K, V); N]> for HashMap` (and friends) In addition to allowing HashMap to participate in Into/From conversion, this adds the long-requested ability to use constructor-like syntax for initializing a HashMap: ```rust let map = HashMap::from([ (1, 2), (3, 4), (5, 6) ]); ``` This addition is highly motivated by existing precedence, e.g. it is already possible to similarly construct a Vec from a fixed-size array: ```rust let vec = Vec::from([1, 2, 3]); ``` ...and it is already possible to collect a Vec of tuples into a HashMap (and vice-versa): ```rust let vec = Vec::from([(1, 2)]); let map: HashMap<_, _> = vec.into_iter().collect(); let vec: Vec<(_, _)> = map.into_iter().collect(); ``` ...and of course it is likewise possible to collect a fixed-size array of tuples into a HashMap ([but not vice-versa just yet](https://github.com/rust-lang/rust/issues/81615)): ```rust let arr = [(1, 2)]; let map: HashMap<_, _> = std::array::IntoIter::new(arr).collect(); ``` Therefore this addition seems like a no-brainer. As for any impl, this would be insta-stable.
2021-07-06Stabilize Vec<T>::shrink_toYoh Deadfall-2/+1
2021-06-30impl From<[(K, V); N]> for std::collectionsbstrie-4/+5
2021-06-30Remove "length" doc aliasesAmanieu d'Antras-1/+0
2021-06-30Remove alloc/malloc/calloc/realloc doc aliasesAmanieu d'Antras-7/+0
2021-06-24Use `hash_one` to simplify some other doctestsScott McMurray-8/+3
2021-06-22Add comments around code where ordering is important due for panic-safetyThe8472-0/+2
Iterators contain arbitrary code which may panic. Unsafe code has to be careful to do its state updates at the right point between calls that may panic.
2021-06-17Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytmYuki Okushi-0/+17
Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec` To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.
2021-06-08Mention the Borrow guarantee on the Hash implementations for Array and VecScott McMurray-0/+17
To remind people like me who forget about it and send PRs to make them different, and to (probably) get a test failure if the code is changed to no longer uphold it.
2021-06-02Update expressions where we can use array's IntoIterator implementationMuhammad Mominul Huque-4/+4
2021-05-24Avoid a double drop in Vec::dedup if a destructor panicsGiacomo Stevanato-2/+3
2021-05-05alloc: Add unstable Cfg feature `no-global_oom_handling`John Ericson-2/+54
For certain sorts of systems, programming, it's deemed essential that all allocation failures be explicitly handled where they occur. For example, see Linus Torvald's opinion in [1]. Merely not calling global panic handlers, or always `try_reserving` first (for vectors), is not deemed good enough, because the mere presence of the global OOM handlers is burdens static analysis. One option for these projects to use rust would just be to skip `alloc`, rolling their own allocation abstractions. But this would, in my opinion be a real shame. `alloc` has a few `try_*` methods already, and we could easily have more. Features like custom allocator support also demonstrate and existing to support diverse use-cases with the same abstractions. A natural way to add such a feature flag would a Cargo feature, but there are currently uncertainties around how std library crate's Cargo features may or not be stable, so to avoid any risk of stabilizing by mistake we are going with a more low-level "raw cfg" token, which cannot be interacted with via Cargo alone. Note also that since there is no notion of "default cfg tokens" outside of Cargo features, we have to invert the condition from `global_oom_handling` to to `not(no_global_oom_handling)`. This breaks the monotonicity that would be important for a Cargo feature (i.e. turning on more features should never break compatibility), but it doesn't matter for raw cfg tokens which are not intended to be "constraint solved" by Cargo or anything else. To support this use-case we create a new feature, "global-oom-handling", on by default, and put the global OOM handler infra and everything else it that depends on it behind it. By default, nothing is changed, but users concerned about global handling can make sure it is disabled, and be confident that all OOM handling is local and explicit. For this first iteration, non-flat collections are outright disabled. `Vec` and `String` don't yet have `try_*` allocation methods, but are kept anyways since they can be oom-safely created "from parts", and we hope to add those `try_` methods in the future. [1]: https://lore.kernel.org/lkml/CAHk-=wh_sNLoz84AUUzuqXEsYH35u=8HV3vK-jbRbJ_B-JjGrg@mail.gmail.com/
2021-04-28Stabilize vec_extend_from_withinAmanieu d'Antras-3/+1
2021-04-21Remove duplicated fn(Box<[T]>) -> Vec<T>Caleb Sander-2/+1
2021-04-18Slightly change wording and fix typo in vec/mod.rsWaffle Lapkin-2/+2
2021-04-12Improve code example for length comparisonGuillaume Gomez-1/+1
2021-03-31panic early when TrustedLen indicates a length > usize::MAXThe8472-0/+8
2021-03-28Auto merge of #83582 - jyn514:might-not, r=joshtriplettbors-3/+3
may not -> might not may not -> might not "may not" has two possible meanings: 1. A command: "You may not stay up past your bedtime." 2. A fact that's only sometimes true: "Some cities may not have bike lanes." In some cases, the meaning is ambiguous: "Some cars may not have snow tires." (do the cars *happen* to not have snow tires, or is it physically impossible for them to have snow tires?) This changes places where the standard library uses the "description of fact" meaning to say "might not" instead. This is just `std::vec` for now - if you think this is a good idea I can convert the rest of the standard library.
2021-03-27may not -> might notJoshua Nelson-3/+3
"may not" has two possible meanings: 1. A command: "You may not stay up past your bedtime." 2. A fact that's only sometimes true: "Some cities may not have bike lanes." In some cases, the meaning is ambiguous: "Some cars may not have snow tires." (do the cars *happen* to not have snow tires, or is it physically impossible for them to have snow tires?) This changes places where the standard library uses the "description of fact" meaning to say "might not" instead. This is just `std::vec` for now - if you think this is a good idea I can convert the rest of the standard library.
2021-03-26Use iter::zip in library/Josh Stone-6/+3
2021-03-25Change wordingMichael Howell-2/+2
2021-03-24Add docs for Vec::from functionsMichael Howell-0/+61
Part of #51430
2021-03-18Rollup merge of #82191 - Soveu:dedup, r=nagisaDylan DPC-6/+89
Vec::dedup_by optimization Now `Vec::dedup_by` drops items in-place as it goes through them. From my benchmarks, it is around 10% faster when T is small, with no major regression when otherwise. I used `ptr::copy` instead of conditional `ptr::copy_nonoverlapping`, because the latter had some weird performance issues on my ryzen laptop (it was 50% slower on it than on intel/sandybridge laptop) It would be good if someone was able to reproduce these results.
2021-03-16Rollup merge of #83072 - henryboisdequin:patch-1, r=Dylan-DPCYuki Okushi-3/+3
Update `Vec` docs Fix typos/nits in `Vec` docs
2021-03-15Merge branch 'master' into dedupSoveu-37/+53
2021-03-15Vec::dedup optimization - finishing polishesSoveu-11/+7