Skip to content

Commit aa77f39

Browse files
committed
Improve the range comparison
As mentioned in #29734, the range comparison closure can be improved. The LLVM IR and the assembly from the new version are much simpler and unfortunately we cannot rely on the compiler to optimise this much, as it would need to know that `lo <= hi`. Besides from simpler code, there might also be a performance advantage, although it is unlikely to appear on benchmarks, as we are doing a binary search, which should always involve few comparisons. The code is available on the playpen for ease of comparison: http://is.gd/4raMmH
1 parent cf3fcf7 commit aa77f39

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/etc/unicode.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,12 @@ def emit_bsearch_range_table(f):
279279
fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool {
280280
use core::cmp::Ordering::{Equal, Less, Greater};
281281
r.binary_search_by(|&(lo, hi)| {
282-
if lo <= c && c <= hi {
283-
Equal
282+
if c < lo {
283+
Greater
284284
} else if hi < c {
285285
Less
286286
} else {
287-
Greater
287+
Equal
288288
}
289289
})
290290
.is_ok()

0 commit comments

Comments
 (0)