diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2010-01-26 14:12:35 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2010-01-26 14:12:35 -0800 |
commit | a0d9dcfe97e824e25174a3bfc9116e505eac0a51 (patch) | |
tree | 3b6bd544c75344f0bdb81f0c34226be77519c129 /lib.c | |
parent | 16a6ea72db8469f64f31903bea7b223f0072bca6 (diff) | |
download | txr-a0d9dcfe97e824e25174a3bfc9116e505eac0a51.tar.gz txr-a0d9dcfe97e824e25174a3bfc9116e505eac0a51.tar.bz2 txr-a0d9dcfe97e824e25174a3bfc9116e505eac0a51.zip |
Optimization in derivative-based regex engine.
Exponential memory consumption behavior was observed when
matching the input aaaaaa....
against the regex a?a?a?a?....aaaa....
The fix is to eliminate common subexpressions
from the derivative for the or operator.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -364,6 +364,13 @@ val memq(val obj, val list) return list; } +val memqual(val obj, val list) +{ + while (list && !equal(car(list), obj)) + list = cdr(list); + return list; +} + val tree_find(val obj, val tree) { if (equal(obj, tree)) @@ -1749,6 +1756,16 @@ val mapcar(val fun, val list) return out; } +val mapcon(val fun, val list) +{ + list_collect_decl (out, iter); + + for (; list; list = cdr(list)) + list_collect_nconc (iter, funcall1(fun, list)); + + return out; +} + val mappend(val fun, val list) { list_collect_decl (out, iter); |