@@ -302,14 +302,31 @@ def gen_combining_class(combining_classes, out):
302302 out .write ("}\n " )
303303
304304def gen_composition_table (canon_comp , out ):
305- out .write ("#[inline]\n " )
305+ table = {}
306+ for (c1 , c2 ), c3 in canon_comp .items ():
307+ if c1 < 0x10000 and c2 < 0x10000 :
308+ table [(c1 << 16 ) | c2 ] = c3
309+ (salt , keys ) = minimal_perfect_hash (table )
306310 out .write ("pub fn composition_table(c1: char, c2: char) -> Option<char> {\n " )
307- out .write (" match (c1, c2) {\n " )
311+ out .write (" if c1 < '\\ u{10000}' && c2 < '\\ u{10000}' {\n " )
312+ out .write (" mph_lookup((c1 as u32) << 16 | (c2 as u32), &[\n " )
313+ for s in salt :
314+ out .write (" 0x{:x},\n " .format (s ))
315+ out .write (" ],\n " )
316+ out .write (" &[\n " )
317+ for k in keys :
318+ out .write (" (0x%s, '\\ u{%s}'),\n " % (hexify (k ), hexify (table [k ])))
319+ out .write (" ],\n " )
320+ out .write (" pair_lookup_fk, pair_lookup_fv_opt, None)\n " )
321+ out .write (" } else {\n " )
322+ out .write (" match (c1, c2) {\n " )
308323
309324 for (c1 , c2 ), c3 in sorted (canon_comp .items ()):
310- out .write (" ('\\ u{%s}', '\\ u{%s}') => Some('\\ u{%s}'),\n " % (hexify (c1 ), hexify (c2 ), hexify (c3 )))
325+ if c1 >= 0x10000 and c2 >= 0x10000 :
326+ out .write (" ('\\ u{%s}', '\\ u{%s}') => Some('\\ u{%s}'),\n " % (hexify (c1 ), hexify (c2 ), hexify (c3 )))
311327
312- out .write (" _ => None,\n " )
328+ out .write (" _ => None,\n " )
329+ out .write (" }\n " )
313330 out .write (" }\n " )
314331 out .write ("}\n " )
315332
0 commit comments