diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-09-28 20:49:01 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-09-28 20:49:01 -0700 |
commit | 9c2cf56174660ec9e5382025003106a4986c8cb4 (patch) | |
tree | 40e34c2b85f7baf6e6c04ac9fd52a42c67530ef4 /regex.c | |
parent | c615ee0cf9790055cfc2d92b50c9f12baaaac2c4 (diff) | |
download | txr-9c2cf56174660ec9e5382025003106a4986c8cb4.tar.gz txr-9c2cf56174660ec9e5382025003106a4986c8cb4.tar.bz2 txr-9c2cf56174660ec9e5382025003106a4986c8cb4.zip |
More complement optimizations.
* regex.c (reg_optimize): Transform ~.*c to (.*[^c])?
and ~c.* to ([^c].*)? where c is a single-character match.
Diffstat (limited to 'regex.c')
-rw-r--r-- | regex.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -1845,6 +1845,25 @@ static val reg_optimize(val exp) cons(invert_single(second(args2)), nil)); } } + + if (cdr(args2) && !cddr(args2)) { + if (reg_matches_all(first(args2)) && + reg_single_char_p(second(args2))) + { + return list(optional_s, + list(compound_s, + cons(zeroplus_s, cons(wild_s, nil)), + invert_single(second(args2)), nao), nao); + } + + if (reg_single_char_p(first(args2)) && + reg_matches_all(second(args2))) { + return list(optional_s, + list(compound_s, + invert_single(first(args2)), + cons(zeroplus_s, cons(wild_s, nil)), nao), nao); + } + } } } return cons(sym, cons(arg, nil)); |