File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 1
1
//! Slice sorting
2
2
//!
3
- //! This module contains an sort algorithm based on Orson Peters' pattern-defeating quicksort,
3
+ //! This module contains a sorting algorithm based on Orson Peters' pattern-defeating quicksort,
4
4
//! published at: https://github.com/orlp/pdqsort
5
5
//!
6
6
//! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our
32
32
F : FnMut ( & T , & T ) -> bool ,
33
33
{
34
34
let len = v. len ( ) ;
35
+ // SAFETY: The unsafe operations below involves indexing without a bound check (`get_unchecked` and `get_unchecked_mut`)
36
+ // and copying memory (`ptr::copy_nonoverlapping`).
37
+ //
38
+ // a. Indexing:
39
+ // 1. We checked the size of the array to >=2.
40
+ // 2. All the indexing that we will do is always between {0 <= index < len} at most.
41
+ //
42
+ // b. Memory copying
43
+ // 1. We are obtaining pointers to references which are guaranteed to be valid.
44
+ // 2. They cannot overlap because we obtain pointers to difference indices of the slice.
45
+ // Namely, `i` and `i-1`.
46
+ // 3. FIXME: Guarantees that the elements are properly aligned?
47
+ //
48
+ // See comments below for further detail.
35
49
unsafe {
36
50
// If the first two elements are out-of-order...
37
51
if len >= 2 && is_less ( v. get_unchecked ( 1 ) , v. get_unchecked ( 0 ) ) {
You can’t perform that action at this time.
0 commit comments