File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 11//! Slice sorting
22//!
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,
44//! published at: https://github.com/orlp/pdqsort
55//!
66//! Unstable sorting is compatible with libcore because it doesn't allocate memory, unlike our
3232 F : FnMut ( & T , & T ) -> bool ,
3333{
3434 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.
3549 unsafe {
3650 // If the first two elements are out-of-order...
3751 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