about summary refs log tree commit diff
path: root/library/alloc/src/vec
AgeCommit message (Collapse)AuthorLines
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-2/+2
2021-07-28Documentation improvementsFrank Steffahn-2/+17
2021-07-28Make `SpecInPlaceCollect` use `TrustedRandomAccessNoCoerce`Frank Steffahn-2/+4
2021-07-28Remove redundant bounds on get_unchecked for vec_deque iterators, and run fmtFrank Steffahn-1/+3
2021-07-28Add back TrustedRandomAccess-specialization for Vec, but only without coercionsFrank Steffahn-1/+33
2021-07-28Remove unsound TrustedRandomAccess implementationsFrank Steffahn-30/+1
Removes the implementations that depend on the user-definable trait `Copy`.
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/+8
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-16Add doc(hidden) to all __iterator_get_uncheckedJacob Hoffman-Andrews-0/+1
This method on the Iterator trait is doc(hidden), and about half of implementations were doc(hidden). This adds the attribute to the remaining implementations.
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-06Rollup merge of #85930 - mominul:array_into_iter, r=m-ou-seYuki Okushi-5/+5
Update standard library for IntoIterator implementation of arrays This PR partially resolves issue #84513 of updating the standard library part. I haven't found any remaining doctest examples which are using iterators over e.g. &i32 instead of just i32 in the standard library. Can anyone point me to them if there's remaining any? Thanks! r? ```@m-ou-se```
2021-06-04Rollup merge of #85717 - fee1-dead:document-cow, r=yaahcYuki Okushi-0/+18
Document `From` impls for cow.rs
2021-06-02Update expressions where we can use array's IntoIterator implementationMuhammad Mominul Huque-5/+5
2021-05-31Update documentation of SpecFromIter to reflect the removed implsFrank Steffahn-3/+1
2021-05-31Remove unnecessary SpecFromIter implsFrank Steffahn-31/+0
2021-05-30Rollup merge of #85817 - r00ster91:patch-9, r=dtolnayGuillaume Gomez-1/+1
Fix a typo See also: #85737
2021-05-30Fix a typor00ster-1/+1
2021-05-27Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum"The8472-59/+25
Due to a performance regression that didn't show up in the original perf run this reverts commit 9111b8ae9793f18179a1336417618fc07a9cac85, reversing changes made to 9a700d2947f2d7f97a2c0dfca3117a8dcc255bdd.
2021-05-27Auto merge of #85737 - scottmcm:vec-calloc-option-nonzero, r=m-ou-sebors-0/+33
Enable Vec's calloc optimization for Option<NonZero> Someone on discord noticed that `vec![None::<NonZeroU32>; N]` wasn't getting the optimization, so here's a PR 🙃 We can certainly do this in the standard library because we know for sure this is ok, but I think it's also a necessary consequence of documented guarantees like those in https://doc.rust-lang.org/std/option/#representation and https://doc.rust-lang.org/core/num/struct.NonZeroU32.html It feels weird to do this without adding a test, but I wasn't sure where that would belong. Is it worth adding codegen tests for these?
2021-05-26Enable Vec's calloc optimization for Option<NonZero>Scott McMurray-0/+33
2021-05-26Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrumbors-25/+59
Add `TrustedRandomAccess` specialization for `Vec::extend()` This should do roughly the same as the `TrustedLen` specialization but result in less IR by using `__iterator_get_unchecked` instead of `Iterator::for_each` Conflicting specializations are manually prioritized by grouping them under yet another helper trait.
2021-05-26Document `From` impls for cow.rsDeadbeef-0/+18
2021-05-24Avoid a double drop in Vec::dedup if a destructor panicsGiacomo Stevanato-2/+3
2021-05-16mark internal inplace_iteration traits as hiddenThe8472-0/+2
2021-05-05alloc: Add unstable Cfg feature `no-global_oom_handling`John Ericson-2/+60
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-15Merge same condition branch in vec spec_extendIvan Tham-4/+2
2021-04-12Improve code example for length comparisonGuillaume Gomez-1/+1
2021-04-08add TrustedRandomAccess specialization to vec::extendThe8472-25/+59
This should do roughly the same as the TrustedLen specialization but result in less IR by using __iterator_get_unchecked instead of iterator.for_each.
2021-04-02Rollup merge of #83629 - the8472:fix-inplace-panic-on-drop, r=m-ou-seDylan DPC-11/+20
Fix double-drop in `Vec::from_iter(vec.into_iter())` specialization when items drop during panic This fixes the double-drop but it leaves a behavioral difference compared to the default implementation intact: In the default implementation the source and the destination vec are separate objects, so they get dropped separately. Here they share an allocation and the latter only exists as a pointer into the former. So if dropping the former panics then this fix will leak more items than the default implementation would. Is this acceptable or should the specialization also mimic the default implementation's drops-during-panic behavior? Fixes #83618 `@rustbot` label T-libs-impl
2021-03-31panic early when TrustedLen indicates a length > usize::MAXThe8472-4/+20
2021-03-29fix double-drop in in-place collect specializationThe8472-11/+20
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