about summary refs log tree commit diff
path: root/src/liballoc/slice.rs
AgeCommit message (Collapse)AuthorLines
2018-06-02Rollup merge of #51147 - tmccombs:sliceindex, r=SimonSapinMark Simulacrum-1/+1
Stabilize SliceIndex trait. CC #35729 According to recommendations in https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-06-01incorporate changes from code reviewEmerentius-11/+13
further reduce unsafe fn calls reduce right drift assert! sufficient capacity
2018-06-01optimize joining and concatenation for slicesEmerentius-11/+11
for both Vec<T> and String - eliminates the boolean first flag in fn join() for String only - eliminates repeated bounds checks in join(), concat() - adds fast paths for small string separators up to a len of 4 bytes
2018-06-01Stabilize SliceIndex trait.Thayne McCombs-1/+1
Fixes #35729 According to recommendations in https://github.com/rust-lang/rust/issues/35729#issuecomment-377784884
2018-05-21Stabilize feature from_refStjepan Glavina-2/+2
2018-05-17Switch to 1.26 bootstrap compilerMark Simulacrum-11/+2
2018-05-09move See also links to topMichael Lamparski-2/+2
2018-04-24Auto merge of #48999 - GuillaumeGomez:add-repeat-on-slice, r=Kimundibors-0/+71
Add repeat method on slice Fixes #48784.
2018-04-21Replace SliceExt with inherent [T] methods in libcoreSimon Sapin-1391/+5
2018-04-21Move non-allocating [u8] inherent methods to libcoreSimon Sapin-54/+4
Fixes #45803
2018-04-17stabilize `swap_with_slice` featuretinaun-7/+1
2018-04-17stabilize `slice_rsplit` featuretinaun-8/+3
2018-04-09Add trivial early return for sort_by_cached_keyvarkor-0/+1
2018-03-28Add repeat method on sliceGuillaume Gomez-0/+71
2018-03-26Remove mentions of unstable sort_by_cached key from stable documentationvarkor-8/+0
2018-03-18Check that the size optimisation is not redundantvarkor-5/+10
2018-03-18Clarify time complexityvarkor-2/+3
2018-03-17Improve and fix documentation for sort_by_cached_keyvarkor-8/+12
2018-03-17Fix use of unstable feature in testvarkor-2/+2
2018-03-16Add sort_by_cached_key methodvarkor-11/+50
2018-03-16Index enumeration by minimally sized typevarkor-12/+25
2018-03-16Cull the quadraticvarkor-0/+1
2018-03-16Update documentationvarkor-10/+11
2018-03-16Clarify behaviour of sort_unstable_by_key with respect to sort_by_keyvarkor-4/+11
2018-03-16Update documentation for sort_by_keyvarkor-7/+4
2018-03-16Compute each key only one during slice::sort_by_keyvarkor-2/+10
2018-02-22Stabilize [T]::rotate_{left,right}Corey Farwell-17/+3
https://github.com/rust-lang/rust/issues/41891
2018-01-21Fix broken links to other slice functions in ↵Sebastian Dröge-0/+8
chunks/chunks_mut/exact_chunk/exact_chunks_mut docs See https://github.com/rust-lang/rust/pull/47126#discussion_r162780492
2018-01-15Rollup merge of #47126 - sdroege:exact-chunks, r=blusskennytm-0/+74
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-13Mention in the exact_chunks docs that this can often be optimized better by ↵Sebastian Dröge-0/+15
the compiler And also link from the normal chunks iterator to the exact_chunks one.
2018-01-13Fix doctests for slice::exact_chunks() for realSebastian Dröge-2/+2
2018-01-13Fix assertions in examples of the exact_chunk() documentationSebastian Dröge-2/+1
2018-01-13Add #![feature(exact_chunks)] to the documentation examples to fix the doc testsSebastian Dröge-0/+4
2018-01-13Add slice::ExactChunks and ::ExactChunksMut iteratorsSebastian Dröge-0/+56
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-13Auto merge of #46461 - zackmdavis:elemental_method_suggestion_jamboree, ↵bors-0/+1
r=estebank type error method suggestions use whitelisted identity-like conversions ![method_jamboree_summit](https://user-images.githubusercontent.com/1076988/33523646-e5c43184-d7c0-11e7-98e5-1bff426ade86.png) Previously, on a type mismatch (and if this wasn't preëmpted by a higher-priority suggestion), we would look for argumentless methods returning the expected type, and list them in a `help` note. This had two major shortcomings: firstly, a lot of the suggestions didn't really make sense (if you used a &str where a String was expected, `.to_ascii_uppercase()` is probably not the solution you were hoping for). Secondly, we weren't generating suggestions from the most useful traits! We address the first problem with an internal `#[rustc_conversion_suggestion]` attribute meant to mark methods that keep the "same value" in the relevant sense, just converting the type. We address the second problem by making `FnCtxt.probe_for_return_type` pass the `ProbeScope::AllTraits` to `probe_op`: this would seem to be safe because grep reveals no other callers of `probe_for_return_type`. Also, structured suggestions are pretty and good for RLS and friends. Unfortunately, the trait probing is still not all one would hope for: at a minimum, we don't know how to rule out `into()` in cases where it wouldn't actually work, and we don't know how to rule in `.to_owned()` where it would. Issues #46459 and #46460 have been filed and are ref'd in a FIXME. This is hoped to resolve #42929, #44672, and #45777.
2018-01-09Rollup merge of #46777 - frewsxcv:frewsxcv-rotate, r=alexcrichtonCorey Farwell-35/+64
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-06type error method suggestions use whitelisted identity-like conversionsZack M. Davis-0/+1
Previously, on a type mismatch (and if this wasn't preëmpted by a higher-priority suggestion), we would look for argumentless methods returning the expected type, and list them in a `help` note. This had two major shortcomings. Firstly, a lot of the suggestions didn't really make sense (if you used a &str where a String was expected, `.to_ascii_uppercase()` is probably not the solution you were hoping for). Secondly, we weren't generating suggestions from the most useful traits! We address the first problem with an internal `#[rustc_conversion_suggestion]` attribute meant to mark methods that keep the "same value" in the relevant sense, just converting the type. We address the second problem by making `FnCtxt.probe_for_return_type` pass the `ProbeScope::AllTraits` to `probe_op`: this would seem to be safe because grep reveals no other callers of `probe_for_return_type`. Also, structured suggestions are preferred (because they're pretty, but also for RLS and friends). Also also, we make the E0055 autoderef recursion limit error use the one-time-diagnostics set, because we can potentially hit the limit a lot during probing. (Without this, test/ui/did_you_mean/recursion_limit_deref.rs would report "aborting due to 51 errors"). Unfortunately, the trait probing is still not all one would hope for: at a minimum, we don't know how to rule out `into()` in cases where it wouldn't actually work, and we don't know how to rule in `.to_owned()` where it would. Issues #46459 and #46460 have been filed and are ref'd in a FIXME. This is hoped to resolve #42929, #44672, and #45777.
2018-01-03Rollup merge of #47125 - daboross:patch-3, r=estebankkennytm-0/+8
Mention SliceConcatExt's stability in its docs Just saw someone in IRC mention there being no stable way to join string slices! It isn't entirely clear from the rust documentation that `SliceConcatExt` is usable. While this is mentioned in https://doc.rust-lang.org/std/prelude/, the trait has nothing to indicate that it's currently usable if found via a documentation search. The wording on this could probably be improved, but I'm hoping its better than nothing.
2018-01-02Mention SliceConcatExt's stability in its docsDavid Ross-0/+8
SliceConcatExt's status as an unstable trait with stable methods is documented in the compiler error for using it, and in https://doc.rust-lang.org/std/prelude/, but it is not mentioned in the trait itself. Mentioning the methods can be used in stable rust today should help users who are looking for a `join` method while working on stable rust.
2018-01-02Consistently use chunk_size as the field name for Chunks and ChunksMutSebastian Dröge-6/+6
Previously Chunks used size and ChunksMut used chunk_size
2017-12-24Deprecate [T]::rotate in favor of [T]::rotate_{left,right}.Corey Farwell-35/+64
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-21Clarify docs for split_at_mutLuc Street-1/+1
The `&mut` here didn't make immediate sense to me. Keep the docs for this function consistent with the non-mut version.
2017-12-02Mark ascii methods on primitive types stable in 1.23.0.Ralph Giles-6/+6
The ascii_methods_on_intrinsics feature stabilization didn't land in time for 1.21.0. Update the annotation so the documentation is correct about when these methods became available.
2017-11-29Update bootstrap compilerAlex Crichton-4/+1
Also remove a number of `stage0` annotations and such
2017-11-29Rollup merge of #46219 - rust-lang:frewsxcv-issue-45636, r=GuillaumeGomezkennytm-13/+106
Improve documentation for slice swap/copy/clone operations. Fixes #45636. - Demonstrate how to use these operations with slices of differing lengths - Demonstrate how to swap/copy/clone sub-slices of a slice using `split_at_mut`
2017-11-29Rollup merge of #46077 - LukasKalbertodt:stabilize-ascii-ctype, r=alexcrichtonkennytm-114/+0
Stabilize some `ascii_ctype` methods As discussed in #39658, this PR stabilizes those methods for `u8` and `char`. All inherent `ascii_ctype` for `[u8]` and `str` are removed as we prefer the more explicit version `s.chars().all(|c| c.is_ascii_())`. This PR doesn't modify the `AsciiExt` trait. There, the `ascii_ctype` methods are still unstable. It is planned to remove those in the future (I think). I had to modify some code in `ascii.rs` to properly implement `AsciiExt` for all types. Fixes #39658.
2017-11-24Improve documentation for slice swap/copy/clone operations.Corey Farwell-13/+106
Fixes #45636. - Demonstrate how to use these operations with slices of differing lengths - Demonstrate how to swap/copy/clone sub-slices of a slice using `split_at_mut`
2017-11-22Rename param in `[T]::swap_with_slice` from `src` to `other`.Corey Farwell-9/+9
The idea of ‘source’ and ‘destination’ aren’t very applicable for this operation since both slices can both be considered sources and destinations.
2017-11-18Remove inherent `ascii_ctype` methods from `str` and `[u8]`Lukas Kalbertodt-114/+0
This has been discussed in #39658. It's a bit ambiguous how those methods work for a sequence of ascii values. We prefer users writing `s.iter().all(|b| b.is_ascii_...())` explicitly. The AsciiExt methods still exist and are implemented for `str` and `[u8]`. We will deprecated or remove those later.
2017-11-03Mark several ascii methods as unstable againLukas Kalbertodt-10/+10
We don't want to stabilize them now already. The goal of this set of commits is just to add inherent methods to the four types. Stabilizing all of those methods can be done later.