Skip to content

Commit e2c84cd

Browse files
committed
Generate code that is friendlier to rustc's item_bodies_checking
Having the Some() constructor in each match arm body puts extras stress on rustc's item_bodies_checking pass. We can work around that by moving the Some() constructor around the match, and directly returning None from the default arm, which is the only one that generates a None value. On my box, this almost cuts the time spent in item_bodies_checking in half, going from about 8.7s to about 4.6s, and reduces the complete compile time from about 13s to about 9s, so about a third less. There are no changes in performance in `cargo bench`. Note that doing the same for the composition_table() function does not yield any compile time wins, but would cause a performance regression. cc #29
1 parent f08c00c commit e2c84cd

File tree

2 files changed

+5753
-5748
lines changed

2 files changed

+5753
-5748
lines changed

scripts/unicode.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,19 @@ def gen_decomposition_tables(canon_decomp, compat_decomp, out):
315315
for table, name in tables:
316316
out.write("#[inline]\n")
317317
out.write("pub fn %s_fully_decomposed(c: char) -> Option<&'static [char]> {\n" % name)
318-
out.write(" match c {\n")
318+
# The "Some" constructor is around the match statement here, because
319+
# putting it into the individual arms would make the item_bodies
320+
# checking of rustc takes almost twice as long, and it's already pretty
321+
# slow because of the huge number of match arms and the fact that there
322+
# is a borrow inside each arm
323+
out.write(" Some(match c {\n")
319324

320325
for char, chars in sorted(table.items()):
321326
d = ", ".join("'\u{%s}'" % hexify(c) for c in chars)
322-
out.write(" '\u{%s}' => Some(&[%s]),\n" % (hexify(char), d))
327+
out.write(" '\u{%s}' => &[%s],\n" % (hexify(char), d))
323328

324-
out.write(" _ => None,\n")
325-
out.write(" }\n")
329+
out.write(" _ => return None,\n")
330+
out.write(" })\n")
326331
out.write("}\n")
327332
out.write("\n")
328333

0 commit comments

Comments
 (0)