Ariel Ben-Yehuda
d8b61091f6
Rollup merge of #41065 - jorendorff:slice-rsplit-41020, r=alexcrichton
...
[T]::rsplit() and rsplit_mut(), #41020
2017-04-05 23:01:13 +00:00
Ariel Ben-Yehuda
9d074473da
Rollup merge of #40943 - Amanieu:offset_to, r=alexcrichton
...
Add ptr::offset_to
This PR adds a method to calculate the signed distance (in number of elements) between two pointers. The resulting value can then be passed to `offset` to get one pointer from the other. This is similar to pointer subtraction in C/C++.
There are 2 special cases:
- If the distance is not a multiple of the element size then the result is rounded towards zero. (in C/C++ this is UB)
- ZST return `None`, while normal types return `Some(isize)`. This forces the user to handle the ZST case in unsafe code. (C/C++ doesn't have ZSTs)
2017-04-05 23:01:08 +00:00
Jason Orendorff
a45fedfa38
simplify implementation of [T]::splitn and friends #41020
2017-04-04 13:40:56 -05:00
Jason Orendorff
2e3f0d8451
add [T]::rsplit() and rsplit_mut() #41020
2017-04-04 13:40:26 -05:00
Amanieu d'Antras
7b89bd7cca
Add ptr::offset_to
2017-04-03 01:36:56 +01:00
bors
a9329d3aa3
Auto merge of #40737 - nagisa:safe-slicing-strs, r=BurntSushi
...
Checked slicing for strings
cc https://github.com/rust-lang/rust/issues/39932
2017-03-31 11:13:20 +00:00
Vadzim Dambrouski
b90936449b
libcore: sort_unstable: remove unnecessary loop.
...
`other` is guaranteed to be less than `2 * len`.
2017-03-28 17:43:01 +03:00
Vadzim Dambrouski
fda8e1571f
libcore: sort_unstable: improve randomization in break_patterns.
...
Select 3 random points instead of just 1.
Also the code now compiles on 16bit architectures.
2017-03-26 20:37:04 +03:00
Stjepan Glavina
2c816f7fb6
Optimize insertion sort
...
This change slightly changes the main iteration loop so that LLVM can
optimize it more efficiently.
Benchmark:
name before ns/iter after ns/iter diff ns/iter diff %
slice::sort_unstable_small_ascending 39 (2051 MB/s) 38 (2105 MB/s) -1 -2.56%
slice::sort_unstable_small_big_random 579 (2210 MB/s) 575 (2226 MB/s) -4 -0.69%
slice::sort_unstable_small_descending 80 (1000 MB/s) 70 (1142 MB/s) -10 -12.50%
slice::sort_unstable_small_random 396 (202 MB/s) 386 -10 -2.53%
2017-03-25 00:32:15 +01:00
Simonas Kazlauskas
2f0dd63bbe
Checked (and unchecked) slicing for strings?
...
What is this magic‽
2017-03-22 18:43:01 +02:00
Stjepan Glavina
d6da1d9b46
Various fixes to wording consistency in the docs
2017-03-22 17:19:52 +01:00
Stjepan Glavina
a718051f63
Unit test heapsort
2017-03-21 20:46:20 +01:00
Stjepan Glavina
02d6e00587
Use partial insertion sort
2017-03-21 20:46:20 +01:00
Stjepan Glavina
c4454a5507
Tweak the constants a bit
2017-03-21 20:46:20 +01:00
Stjepan Glavina
942173b38f
Fix grammar
2017-03-21 20:46:20 +01:00
Stjepan Glavina
cfe6e13b11
Faster sort_unstable on presorted inputs
2017-03-21 20:46:20 +01:00
Stjepan Glavina
e365974750
Address Alex's PR comments
2017-03-21 20:46:20 +01:00
Stjepan Glavina
f1913e2a30
Implement feature sort_unstable
2017-03-21 20:46:20 +01:00