summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-03-01 01:05:05 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-03-01 01:05:05 -0800
commit90fd6a84d08ac95f4886e6ae7e42429f75561bfa (patch)
tree9e5df1c2c6f30fa2d296785fedd39231e4efd85d /match.c
parentaec0b3b3645d241ea8ad1f06dd64716b7d9c3c00 (diff)
downloadtxr-90fd6a84d08ac95f4886e6ae7e42429f75561bfa.tar.gz
txr-90fd6a84d08ac95f4886e6ae7e42429f75561bfa.tar.bz2
txr-90fd6a84d08ac95f4886e6ae7e42429f75561bfa.zip
Fixing two instances of unintentional O(n*n) behavior and poor memory use
that occur in horizontal matching of basic text patterns. * lib.c (match_str, match_str_tree): New functions. * lib.h (match_str, match_str_tree): Declared. * match.c (do_match_line): Use match_str_tree and match_str when matching strings and string lists, respectively, rather than stupidly calling search functions and then asserting that the match was found at the starting position.
Diffstat (limited to 'match.c')
-rw-r--r--match.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/match.c b/match.c
index 736e2bed..a65d6d00 100644
--- a/match.c
+++ b/match.c
@@ -1121,15 +1121,15 @@ static val do_match_line(match_line_ctx *c, val completely)
LOG_MATCH("regex", past);
c->pos = past;
} else if (consp(directive) || stringp(directive)) {
- cons_bind (find, len, search_str_tree(c->dataline, elem, c->pos, nil));
+ val len = match_str_tree(c->dataline, elem, c->pos);
val newpos;
- if (find == nil || !equal(find, c->pos)) {
+ if (!len) {
LOG_MISMATCH("string tree");
debug_return (nil);
}
- newpos = plus(find, len);
+ newpos = plus(c->pos, len);
LOG_MATCH("string tree", newpos);
c->pos = newpos;
} else {
@@ -1182,13 +1182,12 @@ static val do_match_line(match_line_ctx *c, val completely)
break;
case STR:
{
- val find = search_str(c->dataline, elem, c->pos, nil);
val newpos;
- if (find == nil || !equal(find, c->pos)) {
+ if (!match_str(c->dataline, elem, c->pos)) {
LOG_MISMATCH("string");
debug_return (nil);
}
- newpos = plus(find, length_str(elem));
+ newpos = plus(c->pos, length_str(elem));
LOG_MATCH("string", newpos);
c->pos = newpos;
break;