From 3991f471ecd6095cc321c45dff90955d7108970a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 15 Sep 2016 21:45:23 -0700 Subject: regex: add case to complement optimization. * regex.c (reg_optimize): Based on the reasoning in the previous commit, we can also statically optimize a complement whose argument is the t regex: match nothing. We convert that to match everything: the .* regex. Now (regex-compile "~[]") -> #/.*/. --- regex.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/regex.c b/regex.c index 61416fb0..24caca48 100644 --- a/regex.c +++ b/regex.c @@ -1897,6 +1897,8 @@ static val reg_optimize(val exp) return t; if (arg == nil) return cons(oneplus_s, cons(wild_s, nil)); + if (arg == t) + return cons(zeroplus_s, cons(wild_s, nil)); if (reg_single_char_p(arg)) return list(or_s, list(optional_s, invert_single(arg), nao), -- cgit v1.2.3