about summary refs log tree commit diff
path: root/src/libcore/slice
AgeCommit message (Collapse)AuthorLines
2018-08-02Auto merge of #52206 - RalfJung:zst-slices, r=alexcrichtonbors-212/+151
slices: fix ZST slice iterators making up pointers; debug_assert alignment in from_raw_parts This fixes the problem that we are fabricating pointers out of thin air. I also managed to share more code between the mutable and shared iterators, while reducing the amount of macros. I am not sure how useful it really is to add a `debug_assert!` in libcore. Everybody gets a release version of that anyway, right? Is there at least a CI job that runs the test suite with a debug version? Fixes #42789
2018-08-02use the same length computation everywhereRalf Jung-21/+10
2018-08-02Introduce another way to compute the length, to fix position codegen regressionRalf Jung-8/+21
2018-08-02simplify len macro: No longer require the typeRalf Jung-12/+19
Also use ident, not expr, to avoid accidental side-effects
2018-08-02macro-inline len() and is_empty() to fix performance regressionsRalf Jung-20/+29
This also changes the IR for nth(), but the new IR actually looks nicer that the old (and it is one instruction shorter).
2018-08-02make the code for nth closer to what it used to beRalf Jung-3/+4
2018-08-02use wrapping_offset; fix logic error in nthRalf Jung-10/+12
2018-08-02commentsRalf Jung-2/+3
2018-08-02slice iterators: ZST iterators no longer just "make up" addressesRalf Jung-211/+128
2018-07-30fix memrchr in miriRalf Jung-10/+16
2018-07-28Auto merge of #52744 - RalfJung:align_offset, r=Kimundibors-10/+7
make memrchr use align_offset I hope I did not screw that up... Cc @oli-obk who authored the original https://github.com/rust-lang/rust/pull/44537 Fixes #50567 (thanks @bjorn3)
2018-07-27use slice::align_toRalf Jung-26/+7
2018-07-26make memrchr use align_offsetRalf Jung-1/+17
2018-07-19fix safety-related comment in slice::rotateRalf Jung-1/+1
2018-07-13Auto merge of #51622 - kennytm:three-field-range-inclusive, r=SimonSapinbors-10/+10
Change RangeInclusive to a three-field struct. Fix #45222. This PR also reverts #48012 (i.e. removed the `try_fold`/`try_rfold` specialization for `RangeInclusive`) because LLVM no longer has trouble recognizing a RangeInclusive loop.
2018-07-13Change RangeInclusive to a three-field struct.kennytm-10/+10
Fix #45222.
2018-07-12Auto merge of #51339 - sdroege:exact-chunks-remainder, r=alexcrichtonbors-8/+40
Add ExactChunks::remainder and ExactChunks::into_remainder These allow to get the leftover items of the slice that are not being iterated as part of the iterator due to not filling a complete chunk. The mutable version consumes the slice because otherwise we would either a) have to borrow the iterator instead of taking the lifetime of the underlying slice, which is not what *any* of the other iterator functions is doing, or b) would allow returning multiple mutable references to the same data The current behaviour of consuming the iterator is consistent with IterMut::into_slice for the normal iterator. ---- This is related to https://github.com/rust-lang/rust/issues/47115#issuecomment-392685177 and the following comments. While there the discussion was first about a way to get the "tail" of the iterator (everything from the slice that is still not iterated yet), this gives kind of unintuitive behaviour and is inconsistent with how the other slice iterators work. Unintuitive because the `next_back` would have no effect on the tail (or otherwise the tail could not include the remainder items), inconsistent because a) generally the idea of the slice iterators seems to be to only ever return items that were not iterated yet (and don't provide a way to access the same item twice) and b) we would return a "flat" `&[T]` slice but the iterator's shape is `&[[T]]` instead, c) the mutable variant would have to borrow from the iterator instead of the underlying slice (all other iterator functions borrow from the underlying slice!) As such, I've only implemented functions to get the remainder. This also allows the implementation to be completely safe still (and around slices instead of raw pointers), while getting the tail would either be inefficient or would have to be implemented around raw pointers. CC @kerollmops
2018-07-11Rollup merge of #51701 - anirudhb:master, r=frewsxcvGuillaume Gomez-0/+6
Better docs for copy_from_slice & clone_from_slice I copy-pasted the text from clone_from_slice to copy_from_slice :smile: @steveklabnik feel free to suggest changes. edit: closes #49769
2018-07-10Change wording for {copy, clone}_from_sliceAnirudh Balaji-6/+6
2018-07-09Add "or destination" to {copy, clone}_from_slice exampleAnirudh Balaji-4/+4
2018-06-30Auto merge of #51717 - Mark-Simulacrum:snap, r=alexcrichtonbors-3/+0
Bootstrap from 1.28.0 beta
2018-06-30Bootstrap from 1.28.0-beta.3Mark Simulacrum-3/+0
2018-06-28Rollup merge of #51765 - jonas-schievink:patch-1, r=KodrAusMark Rousskov-2/+2
Use assert_eq! in copy_from_slice This will print both lengths when the assertion fails instead of just saying that they're different. Output of current stable and nightly (modulo the exact line number): ``` thread 'main' panicked at 'destination and source slices have different lengths', libcore/slice/mod.rs:1645:9 ``` Output after this PR: ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `123`, right: `456`: destination and source slices have different lengths', libcore/slice/mod.rs:1645:9 ``` Note that I have not run the tests locally.
2018-06-27Nit: Remove leading whitespaceAnirudh Balaji-2/+2
2018-06-26migrate codebase to `..=` inclusive range patternsZack M. Davis-3/+3
These were stabilized in March 2018's #47813, and are the Preferred Way to Do It going forward (q.v. #51043).
2018-06-24Make line-breaking more consistent.Anirudh Balaji-8/+6
2018-06-24Use assert_eq! in copy_from_sliceJonas Schievink-2/+2
This will print both lengths when the assertion fails instead of just saying that they're different.
2018-06-22Add explanation for (copy, clone)_from_sliceAnirudh Balaji-0/+8
It elaborates over why we have to slice the 4-size src to 2-size (same as dst).
2018-06-09Be more precise about why references need to be non-null and alignedRalf Jung-1/+1
2018-06-07Improve docs for slice::from_raw_partsRalf Jung-5/+7
2018-06-04Add ExactChunks::remainder and ExactChunks::into_remainderSebastian Dröge-8/+40
These allow to get the leftover items of the slice that are not being iterated as part of the iterator due to not filling a complete chunk. The mutable version consumes the slice because otherwise we would either a) have to borrow the iterator instead of taking the lifetime of the underlying slice, which is not what *any* of the other iterator functions is doing, or b) would allow returning multiple mutable references to the same data The current behaviour of consuming the iterator is consistent with IterMut::into_slice for the normal iterator.
2018-06-04Move slice::exact_chunks directly above exact_chunks_mut for more consistent ↵Sebastian Dröge-35/+35
docs order See https://github.com/rust-lang/rust/issues/47115#issuecomment-392532855
2018-06-03Rollup merge of #51326 - sdroege:slice-iter-cleanup, r=dtolnayMark Simulacrum-16/+22
Various minor slice iterator cleanups See individual commits
2018-06-03Implement TrustedLen for Windows and the 4 Chunks iteratorsSebastian Dröge-0/+15
2018-06-03Remove mention of Slice/SliceMut traits from IterMut documentationSebastian Dröge-3/+1
These don't exist anymore.
2018-06-03Move TrustedLen and FusedIterator impl of Iter/IterMut into macroSebastian Dröge-13/+6
2018-06-01Stabilize SliceIndex trait.Thayne McCombs-2/+30
Fixes #35729 According to recommendations in https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-05-28extend from_raw_parts docs for slices and strs to mention alignment requirementRalf Jung-5/+6
2018-05-23Rollup merge of #50945 - stjepang:stabilize-from-ref, r=SimonSapinkennytm-3/+3
Stabilize feature from_ref Function `from_ref_mut` is now renamed to `from_mut`, as discussed in #45703. Closes #45703. r? @SimonSapin
2018-05-21Make `[T]::len` and `str::len` const fnOliver Schneider-11/+21
2018-05-21Stabilize feature from_refStjepan Glavina-3/+3
2018-05-19Fix warning when building stage0 libcoreDan Robertson-0/+1
When building stage0 a warning will be triggered when compiling libcore due to align_to_offsets not being used.
2018-05-17Remove the intrinsic for align_offsetSimonas Kazlauskas-2/+5
Keep only the language item. This removes some indirection and makes codegen worse for debug builds, but simplifies code significantly, which is a good tradeoff to make, in my opinion. Besides, the codegen can be improved even further with some constant evaluation improvements that we expect to happen in the future.
2018-05-17Implement [T]::align_toSimonas Kazlauskas-20/+162
2018-05-17Change align_offset to support different stridesSimonas Kazlauskas-0/+22
This is necessary if we want to implement `[T]::align_to` and is more useful in general. This implementation effort has begun during the All Hands and represents a month of my futile efforts to do any sort of maths. Luckily, I found the very very nice Chris McDonald (cjm) on IRC who figured out the core formulas for me! All the thanks for existence of this PR go to them! Anyway… Those formulas were mangled by yours truly into the arcane forms you see here to squeeze out the best assembly possible on most of the modern architectures (x86 and ARM were evaluated in practice). I mean, just look at it: *one actual* modulo operation and everything else is just the cheap single cycle ops! Admitedly, the naive solution might be faster in some common scenarios, but this code absolutely butchers the naive solution on the worst case scenario. Alas, the result of this arcane magic also means that the code pretty heavily relies on the preconditions holding true and breaking those preconditions will unleash the UB-est of all UBs! So don’t.
2018-05-17Switch to 1.26 bootstrap compilerMark Simulacrum-728/+259
2018-05-10Rollup merge of #50010 - ExpHP:slice-bounds, r=alexcrichtonAlex Crichton-4/+8
Give SliceIndex impls a test suite of girth befitting the implementation (and fix a UTF8 boundary check) So one day I was writing something in my codebase that basically amounted to `impl SliceIndex for (Bound<usize>, Bound<usize>)`, and I said to myself: *Boy, gee, golly! I never realized bounds checking was so tricky!* At some point when I had around 60 lines of tests for it, I decided to go see how the standard library does it to see if I missed any edge cases. ...That's when I discovered that libcore only had about 40 lines of tests for slicing altogether, and none of them even used `..=`. --- This PR includes: * **Literally the first appearance of the word `get_unchecked_mut` in any directory named `test` or `tests`.** * Likewise the first appearance of `get_mut` used with _any type of range argument_ in these directories. * Tests for the panics on overflow with `..=`. * I wanted to test on `[(); usize::MAX]` as well but that takes linear time in debug mode </3 * A horrible and ugly test-generating macro for the `should_panic` tests that increases the DRYness by a single order of magnitude (which IMO wasn't enough, but I didn't want to go any further and risk making the tests inaccessible to next guy). * Same stuff for str! * Actually, the existing `str` tests were pretty good. I just helped filled in the holes. * [A fix for the bug it caught](https://github.com/rust-lang/rust/issues/50002). (only one ~~sadly~~)
2018-05-06Move the tests in src/libcore/slice/memchr.rs as well.kennytm-82/+0
2018-05-02nano-optimization for memchr::repeat_byteAndre Bogus-13/+2
2018-04-30str/slice: factor out overflow error messagesMichael Lamparski-4/+8