@@ -33,7 +33,7 @@ struct CharRef {
33
33
}
34
34
35
35
// Build the map from entity names (and their prefixes) to characters.
36
- fn build_map ( js : Json ) -> Option < HashMap < String , [ u32 ; 2 ] > > {
36
+ fn build_map ( js : Json ) -> Option < HashMap < String , ( u32 , u32 ) > > {
37
37
let mut map = HashMap :: new ( ) ;
38
38
let json_map = match js {
39
39
Json :: Object ( m) => m,
@@ -47,24 +47,23 @@ fn build_map(js: Json) -> Option<HashMap<String, [u32; 2]>> {
47
47
= Decodable :: decode ( & mut decoder) . ok ( ) . expect ( "bad CharRef" ) ;
48
48
49
49
assert ! ( ( codepoints. len( ) >= 1 ) && ( codepoints. len( ) <= 2 ) ) ;
50
- let mut codepoint_pair = [ 0 , 0 ] ;
51
- for ( i, n) in codepoints. into_iter ( ) . enumerate ( ) {
52
- codepoint_pair[ i] = n;
53
- }
50
+ let mut codepoints = codepoints. into_iter ( ) ;
51
+ let codepoint_pair = ( codepoints. next ( ) . unwrap ( ) , codepoints. next ( ) . unwrap_or ( 0 ) ) ;
52
+ assert ! ( codepoints. next( ) . is_none( ) ) ;
54
53
55
54
// Slice off the initial '&'
56
55
assert ! ( k. chars( ) . next( ) == Some ( '&' ) ) ;
57
56
map. insert ( k[ 1 ..] . to_string ( ) , codepoint_pair) ;
58
57
}
59
58
60
59
// Add every missing prefix of those keys, mapping to NULL characters.
61
- map. insert ( "" . to_string ( ) , [ 0 , 0 ] ) ;
60
+ map. insert ( "" . to_string ( ) , ( 0 , 0 ) ) ;
62
61
let keys: Vec < String > = map. keys ( ) . map ( |k| k. to_string ( ) ) . collect ( ) ;
63
62
for k in keys. into_iter ( ) {
64
63
for n in 1 .. k. len ( ) {
65
64
let pfx = k[ ..n] . to_string ( ) ;
66
65
if !map. contains_key ( & pfx) {
67
- map. insert ( pfx, [ 0 , 0 ] ) ;
66
+ map. insert ( pfx, ( 0 , 0 ) ) ;
68
67
}
69
68
}
70
69
}
@@ -111,9 +110,9 @@ pub fn expand(cx: &mut ExtCtxt, sp: Span, tt: &[TokenTree]) -> Box<MacResult+'st
111
110
// Emit a macro invocation of the form
112
111
//
113
112
// phf_map!(k => v, k => v, ...)
114
- let toks: Vec < _ > = map. into_iter ( ) . flat_map ( |( k, [ c0, c1] ) | {
113
+ let toks: Vec < _ > = map. into_iter ( ) . flat_map ( |( k, ( c0, c1) ) | {
115
114
let k = & k[ ..] ;
116
- ( quote_tokens ! ( & mut * cx, $k => [ $c0, $c1] , ) ) . into_iter ( )
115
+ ( quote_tokens ! ( & mut * cx, $k => ( $c0, $c1) , ) ) . into_iter ( )
117
116
} ) . collect ( ) ;
118
117
MacEager :: expr ( quote_expr ! ( & mut * cx, phf_map!( $toks) ) )
119
118
}
0 commit comments