summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-09-15 21:45:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-09-15 21:45:23 -0700
commit0f1d470b1b581e84215e725e62f0655bfbf2722b (patch)
tree68fa3a434225d5307ab1be014795d5399d337ee7 /regex.c
parentaebb4e6b373b6724d56a32466c163e52a1c3c2a6 (diff)
downloadtxr-0f1d470b1b581e84215e725e62f0655bfbf2722b.tar.gz
txr-0f1d470b1b581e84215e725e62f0655bfbf2722b.tar.bz2
txr-0f1d470b1b581e84215e725e62f0655bfbf2722b.zip
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 "~[]") -> #/.*/.
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c2
1 files changed, 2 insertions, 0 deletions
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),