Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's a similar pattern in rust:

    fn loop(a: &[u8]) {
        assert!(a.len >= 20);
        for x in (0..20) {
            let y = a[i];
            //Do something with y
        }
    }
Adding the assert before the loop will remove the bounds checks happening on each iteration.


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: