diff options
author | Luigi Rizzo <rizzo@icir.org> | 2006-03-28 13:46:04 +0000 |
---|---|---|
committer | Luigi Rizzo <rizzo@icir.org> | 2006-03-28 13:46:04 +0000 |
commit | 45edaa4c3a453424623676810fe7655983a66985 (patch) | |
tree | 0b6a73a90857be8dc0c3f620c83d399861a312db /channels/chan_agent.c | |
parent | bf2ae443385fc15af5531484aed19aa9a3eca07f (diff) |
optimize a bit name completion by avoiding repeated calls to
strlen(word), localize variables and normalize the test
for finding the candidate string.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@15516 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_agent.c')
-rw-r--r-- | channels/chan_agent.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 9317aad89..d13b091fb 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -1552,18 +1552,15 @@ static int action_agent_logoff(struct mansession *s, struct message *m) static char *complete_agent_logoff_cmd(const char *line, const char *word, int pos, int state) { - struct agent_pvt *p; - char name[AST_MAX_AGENT]; - int which = 0; - if (pos == 2) { + struct agent_pvt *p; + char name[AST_MAX_AGENT]; + int which = 0, len = strlen(word); + AST_LIST_TRAVERSE(&agents, p, list) { snprintf(name, sizeof(name), "Agent/%s", p->agent); - if (!strncasecmp(word, name, strlen(word))) { - if (++which > state) { - return ast_strdup(name); - } - } + if (!strncasecmp(word, name, len) && ++which > state) + return ast_strdup(name); } } else if (pos == 3 && state == 0) { return ast_strdup("soft"); |