File tree Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Expand file tree Collapse file tree 1 file changed +9
-12
lines changed Original file line number Diff line number Diff line change 12
12
use self :: Mapping :: * ;
13
13
use punycode;
14
14
use std:: ascii:: AsciiExt ;
15
+ use std:: cmp:: Ordering :: { Equal , Less , Greater } ;
15
16
use unicode_normalization:: UnicodeNormalization ;
16
17
use unicode_normalization:: char:: is_combining_mark;
17
18
use unicode_bidi:: { BidiClass , bidi_class} ;
@@ -49,20 +50,16 @@ struct Range {
49
50
}
50
51
51
52
fn find_char ( codepoint : char ) -> & ' static Mapping {
52
- let mut min = 0 ;
53
- let mut max = TABLE . len ( ) - 1 ;
54
- while max > min {
55
- let mid = ( min + max) >> 1 ;
56
- if codepoint > TABLE [ mid] . to {
57
- min = mid;
58
- } else if codepoint < TABLE [ mid] . from {
59
- max = mid;
53
+ let r = TABLE . binary_search_by ( |ref range| {
54
+ if codepoint > range. to {
55
+ Less
56
+ } else if codepoint < range. from {
57
+ Greater
60
58
} else {
61
- min = mid;
62
- max = mid;
59
+ Equal
63
60
}
64
- }
65
- & TABLE [ min ] . mapping
61
+ } ) ;
62
+ r . ok ( ) . map ( |i| & TABLE [ i ] . mapping ) . unwrap ( )
66
63
}
67
64
68
65
fn map_char ( codepoint : char , flags : Flags , output : & mut String , errors : & mut Vec < Error > ) {
You can’t perform that action at this time.
0 commit comments