]> git.lizzy.rs Git - rust.git/commitdiff
Improve the range comparison
authorAndrea Canciani <ranma42@gmail.com>
Mon, 4 Jan 2016 16:35:06 +0000 (17:35 +0100)
committerAndrea Canciani <ranma42@gmail.com>
Mon, 4 Jan 2016 16:51:12 +0000 (17:51 +0100)
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

src/etc/unicode.py

index 57bb36ce994c3fdfadb23fefd83aee105bd66bb2..10b864a902dc0a4bebb166b1d8ec0723fa3f4343 100755 (executable)
@@ -279,12 +279,12 @@ def emit_bsearch_range_table(f):
 fn bsearch_range_table(c: char, r: &'static [(char, char)]) -> bool {
     use core::cmp::Ordering::{Equal, Less, Greater};
     r.binary_search_by(|&(lo, hi)| {
-         if lo <= c && c <= hi {
-             Equal
+         if c < lo {
+             Greater
          } else if hi < c {
              Less
          } else {
-             Greater
+             Equal
          }
      })
      .is_ok()