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

Couldn't a method like `get_unchecked()` be used to avoid the bounds check[0] if you know it's safe?

0: https://doc.rust-lang.org/std/vec/struct.Vec.html#method.get...





Yes. You have to write `unsafe { ... }` around it, so there's an ergonomic penalty plus a more nebulous "sense that you're doing something dangerous that might get some skeptical looks in code review" penalty, but the resulting assembly will be the same as indexing in C.

I figured, but I guess I don't understand this argument then. SQLite as a project already spends a lot of time on quality so doing some `unsafe` blocks with a `// SAFETY:` comment doesn't seem unreasonable if they want to avoid the compiler inserting a panic branch for bounds checks.

If you put unsafe around almost all of your code (array indexing) aren't you better off just writing C?

Perhaps if the only thing you're doing is array indexing? Though I'm not sure that would apply in this particular case anyways.

In many cases LLVM can prove the bounds check is redundant or otherwise is unnecessary and will optimize it away.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

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

Search: