Lzu Tao
bcd18f977b
Move free functions to a new module
2020-09-14 09:35:54 +00:00
Lzu Tao
f376443b8f
Move iterator impls to a new module
2020-09-14 09:35:54 +00:00
Ralf Jung
46767b1665
slice::from_raw_parts: explicitly mention that data must be initialized
2020-09-13 14:02:01 +02:00
bors
8b6838b6e1
Auto merge of #75021 - cuviper:array_chunks_mut, r=scottmcm
...
Add `slice::array_chunks_mut`
This follows `array_chunks` from #74373 with a mutable version, `array_chunks_mut`. The implementation is identical apart from mutability. The new tests are adaptations of the `chunks_exact_mut` tests, plus an inference test like the one for `array_chunks`.
I reused the unstable feature `array_chunks` and tracking issue #74985 , but I can separate that if desired.
r? `@withoutboats`
cc `@lcnr`
2020-09-12 03:59:46 +00:00
Flying-Toast
c66789d572
Capitalize safety comments
2020-09-08 22:26:44 -04:00
bors
f76eda3f01
Auto merge of #76395 - dylni:adjust-documentation-for-slice-check-range, r=jyn514
...
Adjust documentation for slice_check_range
Adjust documentation for #76393 .
2020-09-07 09:16:46 +00:00
Dylan DPC
8ff13f4fd2
Rollup merge of #76309 - lzutao:indent-note, r=jyn514
...
Indent a note to make folding work nicer
Sublime Text folds code based on indentation. It maybe an unnecessary change, but does it look nicer after that ?
2020-09-07 01:18:01 +02:00
Dylan DPC
7ad2b3ab29
Rollup merge of #76287 - lzutao:rm-allowed, r=jyn514
...
Remove an unnecessary allowed lint
It is outdated.
2020-09-07 01:17:48 +02:00
dylni
cf529c767e
Adjust documentation for slice_check_range
2020-09-05 19:53:35 -04:00
Josh Stone
86b9f710d0
Move ArrayChunksMut::get_unchecked per #73565
2020-09-04 20:08:12 -07:00
Josh Stone
21903532ee
Build the slice directly in array_chunks_mut
...
Review discussion found that the concern about aliasing was overblown,
so we can simplify this to cast from one slice to another directly.
2020-09-04 19:51:29 -07:00
Josh Stone
f6a6d2fef6
Add slice::array_chunks_mut
2020-09-04 19:51:29 -07:00
Lzu Tao
dfd219d6e7
Indent a note to make folding work nicer
...
Co-authored-by: Joshua Nelson <joshua@yottadb.com >
2020-09-05 02:17:22 +00:00
bors
ef55a0a92f
Auto merge of #75207 - dylni:add-slice-check-range, r=KodrAus
...
Add `slice::check_range`
This method is useful for [`RangeBounds`] parameters. It's even been [rewritten](22ee68dc58/src/librustc_data_structures/sorted_map.rs (L214) ) [many](22ee68dc58/library/alloc/src/vec.rs (L1299) ) [times](22ee68dc58/library/core/src/slice/mod.rs (L2441) ) in the standard library, sometimes assuming that the bounds won't be [`usize::MAX`].
For example, [`Vec::drain`] creates an empty iterator when [`usize::MAX`] is used as an inclusive end bound:
```rust
assert!(vec![1].drain(..=usize::max_value()).eq(iter::empty()));
```
If this PR is merged, I'll create another to use it for those methods.
[`RangeBounds`]: https://doc.rust-lang.org/std/ops/trait.RangeBounds.html
[`usize::MAX`]: https://doc.rust-lang.org/std/primitive.usize.html#associatedconstant.MAX
[`Vec::drain`]: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain
2020-09-04 12:21:43 +00:00
Lzu Tao
a3ee65f87e
Remove a useless allowed attr
2020-09-04 02:42:50 +00:00
bors
62dad457bc
Auto merge of #73819 - euclio:rustdoc-summaries, r=jyn514,GuillaumeGomez
...
rustdoc: do not use plain summary for trait impls
Fixes #38386 .
Fixes #48332 .
Fixes #49430 .
Fixes #62741 .
Fixes #73474 .
Unfortunately this is not quite ready to go because the newly-working links trigger a bunch of linkcheck failures. The failures are tough to fix because the links are resolved relative to the implementor, which could be anywhere in the module hierarchy.
(In the current docs, these links end up rendering as uninterpreted markdown syntax, so I don't think these failures are any worse than the status quo. It might be acceptable to just add them to the linkchecker whitelist.)
Ideally this could be fixed with intra-doc links ~~but it isn't working for me: I am currently investigating if it's possible to solve it this way.~~ Opened #73829 .
EDIT: This is now ready!
2020-09-03 19:07:38 +00:00
bors
897ef3a0ec
Auto merge of #75936 - sdroege:chunks-exact-construction-bounds-check, r=nagisa
...
Get rid of bounds check in slice::chunks_exact() and related function…
…s during construction
LLVM can't figure out in
let rem = self.len() % chunk_size;
let len = self.len() - rem;
let (fst, snd) = self.split_at(len);
and
let rem = self.len() % chunk_size;
let (fst, snd) = self.split_at(rem);
that the index passed to split_at() is smaller than the slice length and
adds a bounds check plus panic for it.
Apart from removing the overhead of the bounds check this also allows
LLVM to optimize code around the ChunksExact iterator better.
2020-08-31 15:55:13 +00:00
Sebastian Dröge
8d3cf9237d
Improve documentation of slice::get_unchecked() / split_at_unchecked()
...
Thanks to Ivan Tham, who gave the majority of these suggestions during
their review.
2020-08-30 23:13:47 +03:00
Sebastian Dröge
d08996ac54
Get rid of bounds check in slice::chunks_exact() and related functions during construction
...
LLVM can't figure out in
let rem = self.len() % chunk_size;
let len = self.len() - rem;
let (fst, snd) = self.split_at(len);
and
let rem = self.len() % chunk_size;
let (fst, snd) = self.split_at(rem);
that the index passed to split_at() is smaller than the slice length and
adds a bounds check plus panic for it.
Apart from removing the overhead of the bounds check this also allows
LLVM to optimize code around the ChunksExact iterator better.
2020-08-30 23:13:47 +03:00
Sebastian Dröge
30dc32b10e
Add (non-public) slice::split_at_unchecked() and split_at_mut_unchecked()
...
These are unsafe variants of the non-unchecked functions and don't do
any bounds checking.
For the time being these are not public and only a preparation for the
following commit. Making it public and stabilization can follow later
and be discussed in https://github.com/rust-lang/rust/issues/76014 .
2020-08-30 23:13:46 +03:00
Andy Russell
98232ece14
fix broken trait method links
2020-08-30 12:04:43 -04:00
Amjad Alsharafi
300a0072a2
Fix intra-doc path resolution problem in library/alloc/src/slice.rs
...
`alloc::slice` uses `core::slice` functions, documentation are copied
from there and the links as well without resolution. `crate::ptr...`
cannot be resolved in `alloc::slice`, but `ptr` itself is imported in
both `alloc::slice` and `core::slice`, so we used that instead.
2020-08-30 15:22:27 +08:00
Amjad Alsharafi
6aae4a2fe6
Used intra-doc links for ptr#safety occurrences
2020-08-28 11:52:04 +08:00
Amjad Alsharafi
a04e12002a
Used intra-doc links for NonNull::dangling() occurrences
2020-08-28 11:52:04 +08:00
Amjad Alsharafi
8e33137159
Fixes intra-doc same scope links
2020-08-28 11:52:03 +08:00
Amjad Alsharafi
91e4aaa736
Use intra-doc links for core/src/slice.mod.rs
...
- most are using primitive types links, which cannot be used with intra
links at the moment
- also `std` cannot be referenced in any link
2020-08-28 11:52:03 +08:00
Matthew Jasper
dbad8c9368
Use min_specialization in libcore
2020-08-19 20:08:02 +01:00
dylni
d04e6b8de5
Replace ad hoc implementations with slice::check_range
2020-08-16 21:47:12 -04:00
bors
4bb4b96ee7
Auto merge of #74562 - pickfire:is_ascii_branchless, r=nagisa
...
Remove branch in optimized is_ascii
Performs slightly better in short or medium bytes by eliminating
the last branch check on `byte_pos == len` and always check the
last byte as it is always at most one `usize`.
Benchmark, before `libcore`, after `libcore_new`. It improves
medium and short by 1ns but regresses unaligned_tail by 2ns,
either way we can get unaligned_tail have a tiny chance of 1/8
on a 64 bit machine. I don't think we should bet on that, the
probability is worse than dice.
```
test long::case00_libcore ... bench: 38 ns/iter (+/- 1) = 183947 MB/s
test long::case00_libcore_new ... bench: 38 ns/iter (+/- 1) = 183947 MB/s
test long::case01_iter_all ... bench: 227 ns/iter (+/- 6) = 30792 MB/s
test long::case02_align_to ... bench: 40 ns/iter (+/- 1) = 174750 MB/s
test long::case03_align_to_unrolled ... bench: 19 ns/iter (+/- 1) = 367894 MB/s
test medium::case00_libcore ... bench: 5 ns/iter (+/- 0) = 6400 MB/s
test medium::case00_libcore_new ... bench: 4 ns/iter (+/- 0) = 8000 MB/s
test medium::case01_iter_all ... bench: 20 ns/iter (+/- 1) = 1600 MB/s
test medium::case02_align_to ... bench: 6 ns/iter (+/- 0) = 5333 MB/s
test medium::case03_align_to_unrolled ... bench: 5 ns/iter (+/- 0) = 6400 MB/s
test short::case00_libcore ... bench: 7 ns/iter (+/- 0) = 1000 MB/s
test short::case00_libcore_new ... bench: 6 ns/iter (+/- 0) = 1166 MB/s
test short::case01_iter_all ... bench: 5 ns/iter (+/- 0) = 1400 MB/s
test short::case02_align_to ... bench: 5 ns/iter (+/- 0) = 1400 MB/s
test short::case03_align_to_unrolled ... bench: 5 ns/iter (+/- 1) = 1400 MB/s
test unaligned_both::case00_libcore ... bench: 4 ns/iter (+/- 0) = 7500 MB/s
test unaligned_both::case00_libcore_new ... bench: 4 ns/iter (+/- 0) = 7500 MB/s
test unaligned_both::case01_iter_all ... bench: 26 ns/iter (+/- 0) = 1153 MB/s
test unaligned_both::case02_align_to ... bench: 13 ns/iter (+/- 2) = 2307 MB/s
test unaligned_both::case03_align_to_unrolled ... bench: 11 ns/iter (+/- 0) = 2727 MB/s
test unaligned_head::case00_libcore ... bench: 5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_head::case00_libcore_new ... bench: 5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_head::case01_iter_all ... bench: 19 ns/iter (+/- 1) = 1631 MB/s
test unaligned_head::case02_align_to ... bench: 10 ns/iter (+/- 0) = 3100 MB/s
test unaligned_head::case03_align_to_unrolled ... bench: 14 ns/iter (+/- 0) = 2214 MB/s
test unaligned_tail::case00_libcore ... bench: 3 ns/iter (+/- 0) = 10333 MB/s
test unaligned_tail::case00_libcore_new ... bench: 5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_tail::case01_iter_all ... bench: 19 ns/iter (+/- 0) = 1631 MB/s
test unaligned_tail::case02_align_to ... bench: 10 ns/iter (+/- 0) = 3100 MB/s
test unaligned_tail::case03_align_to_unrolled ... bench: 13 ns/iter (+/- 0) = 2384 MB/s
```
Rough (unfair) maths on improvements for fun: 1ns * 7/8 - 2ns * 1/8 = 0.625ns
Inspired by fish and zsh clever trick to highlight missing linefeeds (⏎)
and branchless implementation of binary_search in rust.
cc @thomcc https://github.com/rust-lang/rust/pull/74066
r? @nagisa
2020-08-16 23:52:32 +00:00
Lukas Kalbertodt
db99f98c3e
Put panic code path from copy_from_slice into cold function
...
The previous `assert_eq` generated quite some code, which is especially
problematic when this call is inlined. This commit also slightly
improves the panic message from:
assertion failed: `(left == right)`
left: `3`,
right: `2`: destination and source slices have different lengths
...to:
source slice length (2) does not match destination slice length (3)
2020-08-12 21:12:21 +02:00
Poliorcetics
a308e74e13
Add some texts to make the tidy check for unsafe documentation pass
2020-08-11 21:37:22 +02:00
Alexis Bourget
91ba92b6df
Change safety comment for usize with the one from LukasKalbertodt review
2020-08-11 21:23:00 +02:00
Ivan Tham
8ec348afdd
Remove branch in optimized is_ascii
...
Performs slightly better in short or medium bytes by eliminating
the last branch check on `byte_pos == len` and always check the
last byte as it is always at most one `usize`.
Benchmark, before `libcore`, after `libcore_new`. It improves
medium and short by 1ns but regresses unaligned_tail by 2ns,
either way we can get unaligned_tail have a tiny chance of 1/8
on a 64 bit machine. I don't think we should bet on that, the
probability is worse than dice.
test long::case00_libcore ... bench: 38 ns/iter (+/- 1) = 183947 MB/s
test long::case00_libcore_new ... bench: 38 ns/iter (+/- 1) = 183947 MB/s
test long::case01_iter_all ... bench: 227 ns/iter (+/- 6) = 30792 MB/s
test long::case02_align_to ... bench: 40 ns/iter (+/- 1) = 174750 MB/s
test long::case03_align_to_unrolled ... bench: 19 ns/iter (+/- 1) = 367894 MB/s
test medium::case00_libcore ... bench: 5 ns/iter (+/- 0) = 6400 MB/s
test medium::case00_libcore_new ... bench: 4 ns/iter (+/- 0) = 8000 MB/s
test medium::case01_iter_all ... bench: 20 ns/iter (+/- 1) = 1600 MB/s
test medium::case02_align_to ... bench: 6 ns/iter (+/- 0) = 5333 MB/s
test medium::case03_align_to_unrolled ... bench: 5 ns/iter (+/- 0) = 6400 MB/s
test short::case00_libcore ... bench: 7 ns/iter (+/- 0) = 1000 MB/s
test short::case00_libcore_new ... bench: 6 ns/iter (+/- 0) = 1166 MB/s
test short::case01_iter_all ... bench: 5 ns/iter (+/- 0) = 1400 MB/s
test short::case02_align_to ... bench: 5 ns/iter (+/- 0) = 1400 MB/s
test short::case03_align_to_unrolled ... bench: 5 ns/iter (+/- 1) = 1400 MB/s
test unaligned_both::case00_libcore ... bench: 4 ns/iter (+/- 0) = 7500 MB/s
test unaligned_both::case00_libcore_new ... bench: 4 ns/iter (+/- 0) = 7500 MB/s
test unaligned_both::case01_iter_all ... bench: 26 ns/iter (+/- 0) = 1153 MB/s
test unaligned_both::case02_align_to ... bench: 13 ns/iter (+/- 2) = 2307 MB/s
test unaligned_both::case03_align_to_unrolled ... bench: 11 ns/iter (+/- 0) = 2727 MB/s
test unaligned_head::case00_libcore ... bench: 5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_head::case00_libcore_new ... bench: 5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_head::case01_iter_all ... bench: 19 ns/iter (+/- 1) = 1631 MB/s
test unaligned_head::case02_align_to ... bench: 10 ns/iter (+/- 0) = 3100 MB/s
test unaligned_head::case03_align_to_unrolled ... bench: 14 ns/iter (+/- 0) = 2214 MB/s
test unaligned_tail::case00_libcore ... bench: 3 ns/iter (+/- 0) = 10333 MB/s
test unaligned_tail::case00_libcore_new ... bench: 5 ns/iter (+/- 0) = 6200 MB/s
test unaligned_tail::case01_iter_all ... bench: 19 ns/iter (+/- 0) = 1631 MB/s
test unaligned_tail::case02_align_to ... bench: 10 ns/iter (+/- 0) = 3100 MB/s
test unaligned_tail::case03_align_to_unrolled ... bench: 13 ns/iter (+/- 0) = 2384 MB/s
Rough (unfair) maths on improvements for fun: 1ns * 7/8 - 2ns * 1/8 = 0.625ns
Inspired by fish and zsh clever trick to highlight missing linefeeds (⏎)
and branchless implementation of binary_search in rust.
2020-08-11 14:40:39 +08:00
Alexis Bourget
5a0de2f828
Improve safety comments for usize, fix some other unclear parts
2020-08-09 16:43:24 +02:00
Alexis Bourget
3a709fe702
Add precisions about ZSTs and fix nits raised in review
2020-08-08 15:40:10 +02:00
dylni
ed02b90e9b
Fix links again
2020-08-06 14:14:29 -04:00
dylni
202b242d87
Fix links
2020-08-05 23:16:18 -04:00
dylni
bb70e52f5f
Add slice::check_range
2020-08-05 22:32:45 -04:00
Alexis Bourget
92b1975eaa
Added the missing SAFETY: comments
2020-08-03 22:16:50 +02:00
Alexis Bourget
430f19a82e
Document unsafety in library/core/src/slice/mod.rs
2020-08-02 20:03:48 +02:00
Bastian Kauschke
d51b71a35a
add tracking issue
2020-08-01 07:49:24 +02:00
Bastian Kauschke
e75ffb0f1c
use Iter<'_, [T; N]> in array_chunks
2020-07-31 08:25:23 +02:00
Bastian Kauschke
a410ebc5ea
add note to array_chunks
2020-07-31 08:24:57 +02:00
Bastian Kauschke
d27007fd6d
add tests for array_chunks
2020-07-30 10:50:34 +02:00
Bastian Kauschke
d405347f09
adds slice::array_chunks
2020-07-30 10:50:34 +02:00
Bastian Kauschke
870b7cbb11
improve chunks + windows err on size 0
2020-07-30 10:50:34 +02:00
mark
2c31b45ae8
mv std libs to library/
2020-07-27 19:51:13 -05:00