summary refs log tree commit diff
path: root/src/libcore/slice
AgeCommit message (Collapse)AuthorLines
2019-06-20Rollup merge of #60772 - timvermeulen:slice_iter_nth_back, r=scottmcmMazdak Farrokhzad-21/+55
Implement nth_back for slice::{Iter, IterMut} Part of #54054. I implemented `nth_back` as straightforwardly as I could, and then slightly changed `nth` to match `nth_back`. I believe I did so correctly, but please double-check 🙂 I also added the helper methods `zst_shrink`, `next_unchecked`, and `next_back_unchecked` to get rid of some duplicated code. These changes hopefully make this code easier to understand for new contributors like me. I noticed the `is_empty!` and `len!` macros which sole purpose seems to be inlining, according to the comment right above them, but the `is_empty` and `len` methods are already marked with `#[inline(always)]`. Does that mean we could replace these macros with method calls, without affecting anything? I'd love to get rid of them.
2019-06-19Add functions to build raw slicesOliver Scherer-16/+3
2019-06-15Help LLVM better optimize slice::Iter(Mut)::lenScott McMurray-4/+17
2019-06-13Rollup merge of #61398 - kennytm:stabilize-copy-within, r=SimonSapinMazdak Farrokhzad-4/+3
Stabilize copy_within Closes #54236.
2019-06-10core: use memcmp optimization for 128 bit integer slicesAndrew Champion-1/+1
2019-06-02copy_within: replace element access by pointer arithmetic to avoid UBkennytm-2/+2
This ensures we won't accidentally read *src or *dest even when count = 0.
2019-05-31Stabilize copy_withinkennytm-2/+1
2019-05-29Rollup merge of #61048 - wizAmit:feature/nth_back_chunks, r=scottmcmMazdak Farrokhzad-0/+18
Feature/nth back chunks A succinct implementation for nth_back on chunks. Thank you @timvermeulen for the guidance. r? @timvermeulen
2019-05-29Rollup merge of #60555 - timvermeulen:rchunks_nth_back, r=scottmcmMazdak Farrokhzad-0/+72
Implement nth_back for RChunks(Exact)(Mut) Part of #54054. These implementations may not be optimal because of the use of `self.len()`, but it's quite cheap and simplifies the code a lot. There's quite some duplication going on here, I wouldn't mind cleaning this up later. A good next step would probably be to add private `split_off_up_to`/`split_off_from` helper methods for slices since their behavior is commonly useful throughout the `Chunks` types. r? @scottmcm
2019-05-25Implement nth_back for slice::{Iter, IterMut}Tim Vermeulen-21/+55
2019-05-22Revert "Add implementations of last in terms of next_back on a bunch of ↵Steven Fackler-20/+0
DoubleEndedIterators." This reverts commit 3e86cf36b5114f201868bf459934fe346a76a2d4.
2019-05-22succint implementationwizAmit-0/+18
2019-05-22wip nth_back on chunks@amit.chandra-17/+0
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-22hopefully working nth_back on chunks@amit.chandra-8/+9
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-22wip nth_back on chunks@amit.chandra-0/+16
Signed-off-by: wizAmit <amitforfriends_dns@yahoo.com>
2019-05-14Rollup merge of #60443 - RalfJung:as_ptr, r=SimonSapinMazdak Farrokhzad-0/+6
as_ptr returns a read-only pointer Add comments to `as_ptr` methods to warn that these are read-only pointers, and writing to them is UB. [It was pointed out](https://internals.rust-lang.org/t/as-ptr-vs-as-mut-ptr/9940) that `CStr` does not even have an `as_mut_ptr`. I originally was going to add one, but there is no method at all that would mutate a `CStr`. Was that a deliberate choice or should I add an `as_mut_ptr` (similar to [what I did for `str`](https://github.com/rust-lang/rust/pull/58200))?
2019-05-14Rollup merge of #60130 - khuey:efficient_last, r=sfacklerMazdak Farrokhzad-0/+20
Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators Provided a `DoubleEndedIterator` has finite length, `Iterator::last` is equivalent to `DoubleEndedIterator::next_back`. But searching forwards through the iterator when it's unnecessary is obviously not good for performance. I ran into this on one of the collection iterators. I tried adding appropriate overloads for a bunch of the iterator adapters like filter, map, etc, but I ran into a lot of type inference failures after doing so. The other interesting case is what to do with `Repeat`. Do we consider it part of the contract that `Iterator::last` will loop forever on it? The docs do say that the iterator will be evaluated until it returns None. This is also relevant for the adapters, it's trivially easy to observe whether a `Map` adapter invoked its closure a zillion times or just once for the last element.
2019-05-05Implement nth_back for RChunks(Exact)(Mut)Tim Vermeulen-0/+72
2019-05-02clarify wordingRalf Jung-2/+2
2019-05-01as_ptr returns a read-only pointerRalf Jung-0/+6
2019-04-25ignore-tidy-filelength on all files with greater than 3000 linesvarkor-0/+2
2019-04-19Add implementations of last in terms of next_back on a bunch of ↵Kyle Huey-0/+20
DoubleEndedIterators. r?Manishearth
2019-04-19Rollup merge of #60098 - Centril:libcore-deny-more, r=varkorMazdak Farrokhzad-29/+29
libcore: deny `elided_lifetimes_in_paths` r? @varkor
2019-04-19Rollup merge of #60080 - nathankleyn:fix-issue-60068, r=CentrilMazdak Farrokhzad-3/+3
Fix small errors in docs for `rchunks_exact` and `rchunks_exact_mut`. The documentation for `rchunks_exact` said it started at the beginning of the slice, bit it actually starts at the end of the slice. In addition, there were a couple of "of the slice of the slice" duplicate phrases going on for `rchunks_exact` and `rchunks_exact_mut`. This fixes #60068.
2019-04-19libcore: deny more...Mazdak Farrokhzad-29/+29
2019-04-18Fix small errors in docs for `rchunks_exact` and `rchunks_exact_mut`.Nathan Kleyn-3/+3
The documentation for `rchunks_exact` said it started at the beginning of the slice, bit it actually starts at the end of the slice. In addition, there were a couple of "of the slice of the slice" duplicate phrases going on for `rchunks_exact` and `rchunks_exact_mut`. This fixes #60068.
2019-04-18libcore => 2018Taiki Endo-33/+34
2019-04-03Rollup merge of #55448 - Mokosha:SortAtIndex, r=blussMazdak Farrokhzad-0/+236
Add 'partition_at_index/_by/_by_key' for slices. This is an analog to C++'s std::nth_element (a.k.a. quickselect). Corresponds to tracking bug #55300.
2019-03-26adjust MaybeUninit API to discussionsRalf Jung-1/+1
uninitialized -> uninit into_initialized -> assume_init read_initialized -> read set -> write
2019-03-24Rollup merge of #59328 - koalatux:iter-nth-back, r=scottmcmkennytm-0/+13
Implement specialized nth_back() for Box and Windows. Hi there, this is my first pull request to rust :-) I started implementing some specializations for DoubleEndedIterator::nth_back() and these are the first two. The problem has been discussed in #54054 and nth_back() is tracked in #56995. I'm stuck with the next implementation so I though I do a PR for the ones I'm confident with to get some feedback.
2019-03-11Add initial implementation of 'sort_at_index' for slices -- analog to C++'s ↵Pavel Krajcevski-0/+236
std::nth_element (a.k.a. quickselect) Add some more notes to the documentation: - Mention that the median can be found if we used `len() / 2`. - Mention that this function is usually called "kth element" in other libraries. Address some comments in PR: - Change wording on some of the documentation - Change recursive function into a loop Update name to `partition_at_index` and add convenience return values. Address reviewer comments: - Don't swap on each iteration when searching for min/max element. - Add some docs about when we panic. - Test that the sum of the lengths of the output matches the length of the input. - Style fix for for-loop. Address more reviewer comments Fix Rng stuff for test Fix doc test build Don't run the partition_at_index test on wasm targets Miri does not support entropy for test partition_at_index
2019-03-05Add a tracking issue for new as_slice methodsJosh Stone-1/+1
2019-03-05Clean up the example on slice::IterMut::as_slice()Josh Stone-6/+2
2019-03-05Apply suggestions from code reviewMazdak Farrokhzad-4/+4
Co-Authored-By: cuviper <cuviper@gmail.com>
2019-03-04Add as_slice() to slice::IterMut and vec::DrainJosh Stone-0/+32
In bluss/indexmap#88, we found that there was no easy way to implement `Debug` for our `IterMut` and `Drain` iterators. Those are built on `slice::IterMut` and `vec::Drain`, which implement `Debug` themselves, but have no other way to access their data. With a new `as_slice()` method, we can read the data and customize its presentation.
2019-02-25heading # Unsafety => # Safety in stdlib docs.Mazdak Farrokhzad-2/+2
2019-02-24implement nth_back for WindowsAdrian Friedli-0/+13
2019-02-20Rollup merge of #58553 - scottmcm:more-ihle, r=Centrilkennytm-16/+16
Use more impl header lifetime elision Inspired by seeing explicit lifetimes on these two: - https://doc.rust-lang.org/nightly/std/slice/struct.Iter.html#impl-FusedIterator - https://doc.rust-lang.org/nightly/std/primitive.u32.html#impl-Not And a follow-up to https://github.com/rust-lang/rust/pull/54687, that started using IHLE in libcore. Most of the changes in here fall into two big categories: - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop`, `Debug`, and `Clone`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations [where the flipped one cannot elide the lifetime](https://internals.rust-lang.org/t/impl-type-parameter-aliases/9403/2?u=scottmcm). I also removed two lifetimes that turned out to be completely unused; see https://github.com/rust-lang/rust/issues/41960#issuecomment-464557423
2019-02-17Use more impl header lifetime elisionScott McMurray-16/+16
There are two big categories of changes in here - Removing lifetimes from common traits that can essentially never user a lifetime from an input (particularly `Drop` & `Debug`) - Forwarding impls that are only possible because the lifetime doesn't matter (like `impl<R: Read + ?Sized> Read for &mut R`) I omitted things that seemed like they could be more controversial, like the handful of iterators that have a `Item: 'static` despite the iterator having a lifetime or the `PartialEq` implementations where the flipped one cannot elide the lifetime.
2019-02-12Revert "Remove mentions of unstable sort_by_cached key from stable ↵Scott McMurray-0/+4
documentation" This reverts commit 9c7b69e17909ceb090a1c4b8882a4e0924a2a755.
2019-02-10libs: doc commentsAlexander Regueiro-5/+5
2019-02-10tests: doc commentsAlexander Regueiro-7/+7
2019-01-28rename first_mut_ptr -> first_ptr_mutRalf Jung-4/+4
2019-01-28add macro for creating uninitialized arrayRalf Jung-9/+2
2019-01-28libcore: avoid mem::uninitialized and raw ptr castsRalf Jung-6/+13
2019-01-22Move TrustedRandomAccess into Zip moduleClar Fon-1/+0
2019-01-22Rollup merge of #57604 - alercah:str-index, r=sfacklerMazdak Farrokhzad-3/+13
Make `str` indexing generic on `SliceIndex`. Fixes #55603
2019-01-19Make `str` indexing generic on `SliceIndex`.Alexis Hunt-3/+13
2019-01-17Override `Iterator::is_sorted_by` in `slice::Iter` implLukas Kalbertodt-13/+22
Additionally, the root implementation was changed a bit: it now uses `all` instead of coding that logic manually. To avoid duplicate code, the inherent `[T]::is_sorted_by` method now calls `self.iter().is_sorted_by(...)`. This should always be inlined and not result in overhead.
2019-01-17Compare pairs with `slice::windows`Kevin Leimkuhler-7/+5