about summary refs log tree commit diff
path: root/src/libcore/slice
AgeCommit message (Collapse)AuthorLines
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
2018-04-25Fix typez4v1er-1/+0
2018-04-21Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)Simon Sapin-2/+5
`Float` still needs to be public for libcore unit tests.
2018-04-21Replace SliceExt with inherent [T] methods in libcoreSimon Sapin-0/+1404
2018-04-21Move non-allocating [u8] inherent methods to libcoreSimon Sapin-0/+65
Fixes #45803
2018-04-17stabilize `swap_with_slice` featuretinaun-1/+1
2018-04-17stabilize `slice_rsplit` featuretinaun-14/+14
2018-03-31Deprecate offset_to; switch core&alloc to using offset_from insteadScott McMurray-5/+6
Bonus: might make code than uses `.len()` on slice iterators faster
2018-03-15Stabilize `inclusive_range` library feature.kennytm-2/+2
Stabilize std::ops::RangeInclusive and std::ops::RangeInclusiveTo.
2018-03-06Rollup merge of #47463 - bluss:fused-iterator, r=alexcrichtonkennytm-12/+10
Stabilize FusedIterator FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate. Closes #35602
2018-03-03Auto merge of #48583 - dotdash:jt_assume, r=alexcrichtonbors-15/+9
Backport LLVM fixes for a JumpThreading / assume intrinsic bug This fixes the original cause of #48116 and restores the assume intrinsic that was removed as a workaround. r? @alexcrichton
2018-03-03core: Update stability attributes for FusedIteratorUlrik Sverdrup-12/+10
2018-03-03core: Stabilize FusedIteratorUlrik Sverdrup-12/+12
FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate.
2018-02-27Backport LLVM fixes for a JumpThreading / assume intrinsic bugBjörn Steinbrink-15/+9
2018-02-22Stabilize [T]::rotate_{left,right}Corey Farwell-2/+2
https://github.com/rust-lang/rust/issues/41891
2018-02-15Partially revert #47333.kennytm-9/+15
Removed the `assume()` which we assumed is the cause of misoptimization in issue #48116.
2018-01-28Auto merge of #47772 - arthurprs:iter-position-bounds-check, r=dtolnaybors-2/+4
Use the slice length to hint the optimizer about iter.position result Using the len of the iterator doesn't give the same result. That's also why we can't generalize it to all TrustedLen iterators. Problem demo: https://godbolt.org/g/MXg2ae Fix demo: https://godbolt.org/g/P8q5aZ Second attempt of #47333 Third attempt of #45501 Fixes #45964
2018-01-26Use the slice length to hint the optimizerarthurprs-2/+4
Using the len of the iterator doesn't give the same result. That's also why we can't generalize it to all TrustedLen iterators.
2018-01-18Rollup merge of #47404 - integer32llc:reexport-to-re-export, r=steveklabnikkennytm-1/+1
Standardize on "re-export" rather than "reexport" While working on the book with our editors, it was brought to our attention that we're not consistent with when we use "re-export" versus "reexport". For the book, we've decided (with our editors) to go with "re-export"; in prose, I think that looks better. In code, I'm fine with "reexport". However, the rustdoc generated section is currently "Reexports", so when we have a screenshot of generated documentation with the prose where we use "re-export", it's inconsistent. It's too late to fix this for the book because we're using 1.21.0 for the output in the book, and it's really only one spot so it's not a huge deal, but I'd like to advocate for changing the documentation header so that a future edition of the book can be consistent. The first commit here only changes the documentation section heading text and rustdoc documentation that references it. This is the commit that's most important to me. The second commit changes error messages and associated tests to also be consistent with the use of re-export. This is the next most important commit to me, but I could be argued out of this one because then it won't match code like the `macro_reexports` feature name, which ostensibly should change to `macro_re_exports` to be most consistent but I didn't want to change code. The last commit changes re-export anywhere else in prose: either in documentation comments or regular comments. This is least important as most of them aren't user-visible. Instances like these will likely sneak back in over time. I'm totally fine dropping this commit if anyone wants, but [the hobgoblins made me do it](http://www.bartleby.com/100/420.47.html) and it sets a good example. r? @steveklabnik
2018-01-18Rollup merge of #47333 - arthurprs:iter-position-bounds-check, r=dtolnaykennytm-0/+37
Optimize slice.{r}position result bounds check Second attempt of https://github.com/rust-lang/rust/pull/45501 Fixes https://github.com/rust-lang/rust/issues/45964 Demo: https://godbolt.org/g/N4mBHp
2018-01-15Reexport -> re-export in prose and documentation commentsCarol (Nichols || Goulding)-1/+1
2018-01-15Rollup merge of #47126 - sdroege:exact-chunks, r=blusskennytm-0/+225
Add slice::ExactChunks and ::ExactChunksMut iterators These guarantee that always the requested slice size will be returned and any leftoever elements at the end will be ignored. It allows llvm to get rid of bounds checks in the code using the iterator. This is inspired by the same iterators provided by ndarray. Fixes https://github.com/rust-lang/rust/issues/47115 I'll add unit tests for all this if the general idea and behaviour makes sense for everybody. Also see https://github.com/rust-lang/rust/issues/47115#issuecomment-354715511 for an example what this improves.
2018-01-13Implement TrustedRandomAccess for slice::{ExactChunks, ExactChunksMut}Sebastian Dröge-0/+18
2018-01-13Remove useless assertionSebastian Dröge-2/+0
2018-01-13Apply review comments from @blussSebastian Dröge-44/+23
- Simplify nth() by making use of the fact that the slice is evenly divisible by the chunk size, and calling next() instead of duplicating it - Call next_back() in last(), they are equivalent - Implement ExactSizeIterator::is_empty()
2018-01-13Add slice::ExactChunks and ::ExactChunksMut iteratorsSebastian Dröge-0/+230
These guarantee that always the requested slice size will be returned and any leftoever elements at the end will be ignored. It allows llvm to get rid of bounds checks in the code using the iterator. This is inspired by the same iterators provided by ndarray. See https://github.com/rust-lang/rust/issues/47115
2018-01-12Optimize slice.{r}position result bounds checkarthurprs-0/+37
2018-01-09Rollup merge of #46777 - frewsxcv:frewsxcv-rotate, r=alexcrichtonCorey Farwell-2/+15
Deprecate [T]::rotate in favor of [T]::rotate_{left,right}. Background ========== Slices currently have an **unstable** [`rotate`] method which rotates elements in the slice to the _left_ N positions. [Here][tracking] is the tracking issue for this unstable feature. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` Proposal ======== Deprecate the [`rotate`] method and introduce `rotate_left` and `rotate_right` methods. ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_left(2); assert_eq!(a, ['c', 'd', 'e', 'f', 'a', 'b']); ``` ```rust let mut a = ['a', 'b' ,'c', 'd', 'e', 'f']; a.rotate_right(2); assert_eq!(a, ['e', 'f', 'a', 'b', 'c', 'd']); ``` Justification ============= I used this method today for my first time and (probably because I’m a naive westerner who reads LTR) was surprised when the docs mentioned that elements get rotated in a left-ward direction. I was in a situation where I needed to shift elements in a right-ward direction and had to context switch from the main problem I was working on and think how much to rotate left in order to accomplish the right-ward rotation I needed. Ruby’s `Array.rotate` shifts left-ward, Python’s `deque.rotate` shifts right-ward. Both of their implementations allow passing negative numbers to shift in the opposite direction respectively. The current `rotate` implementation takes an unsigned integer argument which doesn't allow the negative number behavior. Introducing `rotate_left` and `rotate_right` would: - remove ambiguity about direction (alleviating need to read docs 😉) - make it easier for people who need to rotate right [`rotate`]: https://doc.rust-lang.org/std/primitive.slice.html#method.rotate [tracking]: https://github.com/rust-lang/rust/issues/41891