From 90fd6a84d08ac95f4886e6ae7e42429f75561bfa Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 1 Mar 2012 01:05:05 -0800 Subject: 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. --- match.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'match.c') 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; -- cgit v1.2.3