| Age | Commit message (Collapse) | Author | Lines |
|
r=joshtriplett
RawVec: don't recompute capacity after allocating.
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.
r? `@ghost`
|
|
|
|
|
|
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.
|
|
The previous implementation used slice::as_mut_ptr_range to derive the
pointer for the spare capacity slice. This is invalid, because that
pointer is derived from the initialized region, so it does not have
provenance over the uninitialized region.
|
|
|
|
Update example code for Vec::splice to change the length
The current example for `Vec::splice` illustrates the replacement of a section of length 2 with a new section of length 2. This isn't a particularly interesting case for splice, and makes it look a bit like a shorthand for the kind of manipulations that could be done with a mutable slice.
In order to provide a stronger example, this updates the example to use different lengths for the source and destination regions, and uses a slice from the middle of the vector to illustrate that this does not necessarily have to be at the beginning or the end.
Resolves #92067
|
|
The src pointers in CopyOnDrop and InsertionHole used to be *mut T, and
were derived via automatic conversion from &mut T. According to Stacked
Borrows 2.1, this means that those pointers become invalidated by
interior mutation in the comparison function.
But there's no need for mutability in this code path. Thus, we can
change the drop guards to use *const and derive those from &T.
|
|
|
|
Add missing `'s` to ` Let check it out.`
|
|
Optimize `vec::retain` performance
This simply moves the loops into the inner function which leads to better results.
```
old:
test vec::bench_retain_100000 ... bench: 203,828 ns/iter (+/- 2,101)
test vec::bench_retain_iter_100000 ... bench: 63,324 ns/iter (+/- 12,305)
test vec::bench_retain_whole_100000 ... bench: 42,989 ns/iter (+/- 291)
new:
test vec::bench_retain_100000 ... bench: 42,180 ns/iter (+/- 451)
test vec::bench_retain_iter_100000 ... bench: 65,167 ns/iter (+/- 11,971)
test vec::bench_retain_whole_100000 ... bench: 33,736 ns/iter (+/- 12,404)
```
Measured on x86_64-unknown-linux-gnu, Zen2
Fixes #91497
|
|
r=jackh726,pnkfelix
Stabilize `destructuring_assignment`
Closes #71126
- [Stabilization report](https://github.com/rust-lang/rust/issues/71126#issuecomment-941148058)
- [Completed FCP](https://github.com/rust-lang/rust/issues/71126#issuecomment-954914819)
`@rustbot` label +F-destructuring-assignment +T-lang
Also needs +relnotes but I don't have permission to add that tag.
|
|
|
|
|
|
add BinaryHeap::try_reserve and BinaryHeap::try_reserve_exact
`try_reserve` of many collections were stablized in https://github.com/rust-lang/rust/pull/87993 in 1.57.0. Add `try_reserve` for the rest collections such as `BinaryHeap` should be not controversial.
|
|
Use spare_capacity_mut instead of invalid unchecked indexing when joining str
This is a fix for https://github.com/rust-lang/rust/issues/91574
I think in general I'd prefer to see this code implemented with raw pointers or `MaybeUninit::write_slice`, but there's existing code in here based on copying from slice to slice, so converting everything from `&[T]` to `&[MaybeUninit<T>]` is less disruptive.
|
|
|
|
BTree: improve public descriptions and comments
BTreeSet has always used the term "value" next to and meaning the same thing as "elements" (in the mathematical sense but also used for key-value pairs in BTreeMap), while in the BTreeMap sense these "values" are known as "keys" and definitely not "values". Today I had enough of that.
r? `@Mark-Simulacrum`
|
|
doc: fix typo in comments
`dereferencable -> dereferenceable`
Fixes #91802.
|
|
Btree: assert more API compatibility
Introducing a member such as `BTreeSet::min()` would silently break compatibility if no code calls the existing `BTreeSet::min(set)`. `BTreeSet` is the only btree class silently bringing in stable members, apart from many occurrences of `#[derive(Debug)]` on iterators.
r? `@Mark-Simulacrum`
|
|
dereferencable -> dereferenceable
|
|
fixes #91772
|
|
|
|
Signed-off-by: TennyZhuang <zty0826@gmail.com>
|
|
Rollup of 11 pull requests
Successful merges:
- #91668 (Remove the match on `ErrorKind::Other`)
- #91678 (Add tests fixed by #90023)
- #91679 (Move core/stream/stream/mod.rs to core/stream/stream.rs)
- #91681 (fix typo in `intrinsics::raw_eq` docs)
- #91686 (Fix `Vec::reserve_exact` documentation)
- #91697 (Delete Utf8Lossy::from_str)
- #91706 (Add unstable book entries for parts of asm that are not being stabilized)
- #91709 (Replace iterator-based set construction by *Set::From<[T; N]>)
- #91716 (Improve x.py logging and defaults a bit more)
- #91747 (Add pierwill to .mailmap)
- #91755 (Fix since attribute for const_linked_list_new feature)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
|
|
r=dtolnay
Fix since attribute for const_linked_list_new feature
https://github.com/rust-lang/rust/pull/63684
was merged for 1.39 not 1.32
|
|
Replace iterator-based set construction by *Set::From<[T; N]>
This uses the array-based construction for `BtreeSet`s and `HashSet`s instead of first creating an iterator. I could also replace the `let mut a = Set::new(); a.insert(...);` fragments if desired.
|
|
Fix `Vec::reserve_exact` documentation
The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.
|
|
Fix Vec::extend_from_slice docs
`other` is a slice not a vector.
|
|
JosephTLyons:update-HashMap-and-BTreeMap-documentation, r=yaahc
Update documentation to use `from()` to initialize `HashMap`s and `BTreeMap`s
As of Rust 1.56, `HashMap` and `BTreeMap` both have associated `from()` functions. I think using these in the documentation cleans things up a bit. It allows us to remove some of the `mut`s and avoids the Initialize-Then-Modify anti-pattern.
|
|
https://github.com/rust-lang/rust/pull/63684
was merged for 1.39 not 1.32
|
|
|
|
|
|
|
|
replace vec::Drain drop loops with drop_in_place
The `Drain::drop` implementation came up in https://github.com/rust-lang/rust/pull/82185#issuecomment-789584796 as potentially interfering with other optimization work due its widespread use somewhere in `println!`
`@rustbot` label T-libs-impl
|
|
|
|
The documentation previously said the new capacity cannot overflow `usize`, but in fact it cannot exceed `isize::MAX`.
|
|
|
|
|
|
Suggest try_reserve in try_reserve_exact
During developing #91529 , I found that `try_reserve_exact` suggests `reserve` for further insertions. I think it's a mistake by copy&paste, `try_reserve` is better here.
|
|
Deprecate array::IntoIter::new.
|
|
Signed-off-by: TennyZhuang <zty0826@gmail.com>
|
|
Implement VecDeque::retain_mut
Part of https://github.com/rust-lang/rust/issues/90829.
In https://github.com/rust-lang/rust/pull/90772, someone suggested that `retain_mut` should also be implemented on `VecDeque`. I think that it follows the same logic (coherency). So first: is it ok? Second: should I create a new feature for it or can we put it into the same one?
r? `@joshtriplett`
|
|
|
|
For users looking at documentation through IDE popups, this gives them
relevant information rather than the generic trait documentation wording
“Performs the conversion”. For users reading the documentation for a
specific type for any reason, this informs them when the conversion may
allocate or copy significant memory versus when it is always a move or
cheap copy.
Notes on specific cases:
* The new documentation for `From<T> for T` explains that it is not a
conversion at all.
* Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other
central blanket implementation of conversion.
* I did not add documentation to conversions of a specific error type to
a more general error type.
* I did not add documentation to unstable code.
This change was prepared by searching for the text "From<... for" and so
may have missed some cases that for whatever reason did not match. I
also looked for `Into` impls but did not find any worth documenting by
the above criteria.
|
|
This simply moves the loops into the inner function which leads to better results.
```
old:
test vec::bench_retain_100000 ... bench: 203,828 ns/iter (+/- 2,101)
test vec::bench_retain_iter_100000 ... bench: 63,324 ns/iter (+/- 12,305)
test vec::bench_retain_whole_100000 ... bench: 42,989 ns/iter (+/- 291)
new:
test vec::bench_retain_100000 ... bench: 42,180 ns/iter (+/- 451)
test vec::bench_retain_iter_100000 ... bench: 65,167 ns/iter (+/- 11,971)
test vec::bench_retain_whole_100000 ... bench: 33,736 ns/iter (+/- 12,404)
```
|
|
|
|
Add unchecked downcast methods
```rust
impl dyn Any (+ Send + Sync) {
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T;
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T;
}
impl<A: Allocator> Box<dyn Any (+ Send + Sync), A> {
pub unsafe fn downcast_unchecked<T: Any>(&self) -> Box<T, A>;
}
```
|
|
|
|
Rollup of 10 pull requests
Successful merges:
- #88906 (Implement write() method for Box<MaybeUninit<T>>)
- #90269 (Make `Option::expect` unstably const)
- #90854 (Type can be unsized and uninhabited)
- #91170 (rustdoc: preload fonts)
- #91273 (Fix ICE #91268 by checking that the snippet ends with a `)`)
- #91381 (Android: -ldl must appear after -lgcc when linking)
- #91453 (Document Windows TLS drop behaviour)
- #91462 (Use try_normalize_erasing_regions in needs_drop)
- #91474 (suppress warning about set_errno being unused on DragonFly)
- #91483 (Sync rustfmt subtree)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
|