summary refs log tree commit diff
path: root/src/libcore/slice
AgeCommit message (Collapse)AuthorLines
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-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
2018-01-04Fix potential overflow in TrustedRandomAccess impl for slice::{Chunks,ChunksMut}Sebastian Dröge-2/+8
2018-01-03Fix compilation of TrustedRandomAccess impl for slice::ChunksSebastian Dröge-2/+2
https://github.com/rust-lang/rust/pull/47113 renamed the private size field to chunk_size for consistency.
2018-01-03Implement TrustedRandomAccess for slice::{Chunks, ChunksMut, Windows}Sebastian Dröge-0/+28
2018-01-03Rollup merge of #47118 - hdhoang:patch-2, r=BurntSushikennytm-2/+2
memchr: fix variable name in docstrings upstream BurntSushi/rust-memchr#24 r=BurntSushi
2018-01-02Use assert!(chunk_size != 0) instead of > 0 for usize valueSebastian Dröge-1/+1
2018-01-02Consistently use chunk_size as the field name for Chunks and ChunksMutSebastian Dröge-15/+15
Previously Chunks used size and ChunksMut used chunk_size
2018-01-01memchr: fix variable name in docstringsHoàng Đức Hiếu-2/+2
2017-12-31Auto merge of #46713 - Manishearth:memchr, r=blussbors-1/+260
Use memchr to speed up [u8]::contains 3x None
2017-12-31Use memchr for [i8]::contains as wellManish Goregaokar-0/+8
2017-12-24Deprecate [T]::rotate in favor of [T]::rotate_{left,right}.Corey Farwell-2/+15
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. 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
2017-12-20docs(slice): Clarify half-open intervalFlorian Keller-1/+1
2017-12-13Support 16 bit platformsManish Goregaokar-0/+6
2017-12-13Use memchr in [u8]::containsManish Goregaokar-1/+17
2017-12-13Move rust memchr impl to libcoreManish Goregaokar-0/+229
2017-11-17Auto merge of #45595 - scottmcm:iter-try-fold, r=dtolnaybors-110/+45
Short-circuiting internal iteration with Iterator::try_fold & try_rfold These are the core methods in terms of which the other methods (`fold`, `all`, `any`, `find`, `position`, `nth`, ...) can be implemented, allowing Iterator implementors to get the full goodness of internal iteration by only overriding one method (per direction). Based off the `Try` trait, so works with both `Result` and `Option` (:tada: https://github.com/rust-lang/rust/pull/42526). The `try_fold` rustdoc examples use `Option` and the `try_rfold` ones use `Result`. AKA continuing in the vein of PRs https://github.com/rust-lang/rust/pull/44682 & https://github.com/rust-lang/rust/pull/44856 for more of `Iterator`. New bench following the pattern from the latter of those: ``` test iter::bench_take_while_chain_ref_sum ... bench: 1,130,843 ns/iter (+/- 25,110) test iter::bench_take_while_chain_sum ... bench: 362,530 ns/iter (+/- 391) ``` I also ran the benches without the `fold` & `rfold` overrides to test their new default impls, with basically no change. I left them there, though, to take advantage of existing overrides and because `AlwaysOk` has some sub-optimality due to https://github.com/rust-lang/rust/issues/43278 (which 45225 should fix). If you're wondering why there are three type parameters, see issue https://github.com/rust-lang/rust/issues/45462 Thanks for @bluss for the [original IRLO thread](https://internals.rust-lang.org/t/pre-rfc-fold-ok-is-composable-internal-iteration/4434) and the rfold PR and to @cuviper for adding so many folds, [encouraging me](https://github.com/rust-lang/rust/pull/45379#issuecomment-339424670) to make this PR, and finding a catastrophic bug in a pre-review.
2017-11-11Auto merge of #45333 - alkis:master, r=blussbors-16/+18
Improve SliceExt::binary_search performance Improve the performance of binary_search by reducing the number of unpredictable conditional branches in the loop. In addition improve the benchmarks to test performance in l1, l2 and l3 caches on sorted arrays with or without dups. Before: ``` test slice::binary_search_l1 ... bench: 48 ns/iter (+/- 1) test slice::binary_search_l2 ... bench: 63 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 152 ns/iter (+/- 12) test slice::binary_search_l1_with_dups ... bench: 36 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 64 ns/iter (+/- 1) test slice::binary_search_l3_with_dups ... bench: 153 ns/iter (+/- 6) ``` After: ``` test slice::binary_search_l1 ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2 ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 100 ns/iter (+/- 17) test slice::binary_search_l1_with_dups ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3_with_dups ... bench: 98 ns/iter (+/- 14) ```
2017-11-11Improve the performance of binary_search by reducing the number ofAlkis Evlogimenos-16/+18
unpredictable conditional branches in the loop. In addition improve the benchmarks to test performance in l1, l2 and l3 caches on sorted arrays with or without dups. Before: ``` test slice::binary_search_l1 ... bench: 48 ns/iter (+/- 1) test slice::binary_search_l2 ... bench: 63 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 152 ns/iter (+/- 12) test slice::binary_search_l1_with_dups ... bench: 36 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 64 ns/iter (+/- 1) test slice::binary_search_l3_with_dups ... bench: 153 ns/iter (+/- 6) ``` After: ``` test slice::binary_search_l1 ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2 ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3 ... bench: 100 ns/iter (+/- 17) test slice::binary_search_l1_with_dups ... bench: 15 ns/iter (+/- 0) test slice::binary_search_l2_with_dups ... bench: 23 ns/iter (+/- 0) test slice::binary_search_l3_with_dups ... bench: 98 ns/iter (+/- 14) ```
2017-11-06Inclusive range updated to `..=` syntaxBadel2-9/+6
2017-11-01De-stabilize core::slice::{from_ref, from_ref_mut}.whitequark-2/+2
2017-10-29Fundamental internal iteration with try_foldScott McMurray-110/+45
This is the core method in terms of which the other methods (fold, all, any, find, position, nth, ...) can be implemented, allowing Iterator implementors to get the full goodness of internal iteration by only overriding one method (per direction).
2017-10-23Bring back slice::ref_slice as slice::from_ref.whitequark-0/+16
These functions were deprecated and removed in 1.5, but such simple functionality shouldn't require using unsafe code, and it isn't cluttering libstd too much.