8000 Merge pull request #16 from nnethercote/speed-up-bsearch_range_table · unicode-rs/unicode-xid@bb14270 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb14270

Browse files
authored
Merge pull request #16 from nnethercote/speed-up-bsearch_range_table
Speed up `bsearch_range_table`.
2 parents 5e0a152 + bffbff6 commit bb14270

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/tables.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ fn bsearch_range_table(c: char, r: &[(char,char)]) -> bool {
2020
use core::cmp::Ordering::{Equal, Less, Greater};
2121

2222
r.binary_search_by(|&(lo,hi)| {
23-
if lo <= c && c <= hi { Equal }
23+
// Because ASCII ranges are at the start of the tables, a search for an
24+
// ASCII char will involve more `Greater` results (i.e. the `(lo,hi)`
25+
// table entry is greater than `c`) than `Less` results. And given that
26+
// ASCII chars are so common, it makes sense to favor them. Therefore,
27+
// the `Greater` case is tested for before the `Less` case.
28+
if lo > c { Greater }
2429
else if hi < c { Less }
25-
else { Greater }
30+
else { Equal }
2631
}).is_ok()
2732
}
2833

@@ -446,6 +451,5 @@ pub mod derived_property {
446451
pub fn XID_Start(c: char) -> bool {
447452
super::bsearch_range_table(c, XID_Start_table)
448453
}
449-
450454
}
451455

0 commit comments

Comments
 (0)
0