My second post
2022-11-10
TODO (Gains!!) TODO (Explanation of library + foreshadowing)
After poking around a bit, I found this function
fn bsearch_range_table(c: char, r: &[(char, char)]) -> bool {
use core::cmp::Ordering::{Equal, Greater, Less};
r.binary_search_by(|&(lo, hi)| {
// Because ASCII ranges are at the start of the tables, a search for an
// ASCII char will involve more `Greater` results (i.e. the `(lo,hi)`
// table entry is greater than `c`) than `Less` results. And given that
// ASCII chars are so common, it makes sense to favor them. Therefore,
// the `Greater` case is tested for before the `Less` case.
if lo > c {
Greater
} else if hi < c {
Less
} else {
Equal
}
})
.is_ok()
}
This uses the standard library's implementation of binary search.
All standard library methods are marked as rust #[inline(always)]
,
so I figured the compiler might see this and figure it's too large to inline.