From 35396ddf01daef0d3dea12f2ed960d9693d58eed Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 27 Sep 2015 22:42:46 -0700 Subject: Optimization for one-character range. * regex.c (reg_optimize): [a] -> a. Also take advantage of this where the complement case generates [a]. --- regex.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/regex.c b/regex.c index a4ca5451..d4cfe00c 100644 --- a/regex.c +++ b/regex.c @@ -1736,7 +1736,11 @@ static val reg_optimize(val exp) val args = rest(exp); if (sym == set_s) { - return if3(rest(exp), exp, t); + if (!args) + return t; + if (!rest(args) && chrp(first(args))) + return first(args); + return exp; } else if (sym == cset_s) { return if3(rest(exp), exp, wild_s); } else if (sym == compound_s) { @@ -1788,7 +1792,8 @@ static val reg_optimize(val exp) val sym2 = first(arg); if (sym2 == cset_s) return list(or_s, - list(optional_s, cons(set_s, rest(arg)), nao), + list(optional_s, reg_optimize(cons(set_s, rest(arg))), + nao), list(compound_s, wild_s, list(oneplus_s, wild_s, nao), nao), nao); if (sym2 == set_s) -- cgit v1.2.3