Unable to optimize bounds checks

Here's another version with bound checks elided. The assembly is pretty weird though.

pub fn bubble_sort_rust(mut array: &mut [u32]) {
    while array.len() >= 2 {
        for i in 1..array.len() {
            if array[i-1] > array[i] {
                array.swap(i-1, i);
            }
        }
        let len = array.len();
        array = &mut array[..len-1];
    }
}
2 Likes