Make hfa::match not need to walk a string twice

Currently hfa::match calls hfa::match_len to do matching.  However this
requires walking the input string twice.  Instead provide a match routine
for input that is supposed to terminate at a given input character.

Signed-off-by: John Johansen <john.johansen@canonical.com>
Acked-By: Steve Beattie <sbeattie@ubuntu.com>
This commit is contained in:
John Johansen 2012-01-06 09:04:36 -08:00
parent 3ff8b4d19a
commit f561b8cdfe
2 changed files with 10 additions and 1 deletions

View file

@ -276,9 +276,17 @@ State *DFA::match_len(State *state, const char *str, size_t len)
return state;
}
State *DFA::match_until(State *state, const char *str, const char term)
{
while (*str != term)
state = state->next(*str++);
return state;
}
State *DFA::match(const char *str)
{
return match_len(start, str, strlen(str));
return match_until(start, str, 0);
}
void DFA::dump_uniq_perms(const char *s)

View file

@ -349,6 +349,7 @@ public:
virtual ~DFA();
State *match_len(State *state, const char *str, size_t len);
State *match_until(State *state, const char *str, const char term);
State *match(const char *str);
void remove_unreachable(dfaflags_t flags);