File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 7676 F : FnMut ( & T , & T ) -> bool ,
7777{
7878 let len = v. len ( ) ;
79+ // SAFETY: As with shift_head, the unsafe operations below involves indexing without a bound check (`get_unchecked` and `get_unchecked_mut`)
80+ // and copying memory (`ptr::copy_nonoverlapping`).
81+ //
82+ // a. Indexing:
83+ // 1. We checked the size of the array to >=2.
84+ // 2. All the indexing that we will do is always between {0 <= index < len-1} at most.
85+ //
86+ // b. Memory copying
87+ // 1. We are obtaining pointers to references which are guaranteed to be valid.
88+ // 2. They cannot overlap because we obtain pointers to difference indices of the slice.
89+ // Namely, `i` and `i+1`.
90+ // 3. FIXME: Guarantees that the elements are properly aligned?
91+ //
92+ // See comments below for further detail.
7993 unsafe {
8094 // If the last two elements are out-of-order...
8195 if len >= 2 && is_less ( v. get_unchecked ( len - 1 ) , v. get_unchecked ( len - 2 ) ) {
You can’t perform that action at this time.
0 commit comments