[asterisk-commits] trunk r15516 - /trunk/channels/chan_agent.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 28 06:46:06 MST 2006


Author: rizzo
Date: Tue Mar 28 07:46:04 2006
New Revision: 15516

URL: http://svn.digium.com/view/asterisk?rev=15516&view=rev
Log:
optimize a bit name completion by avoiding repeated calls to
strlen(word), localize variables and normalize the test
for finding the candidate string.


Modified:
    trunk/channels/chan_agent.c

Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?rev=15516&r1=15515&r2=15516&view=diff
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Tue Mar 28 07:46:04 2006
@@ -1552,18 +1552,15 @@
 
 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");



More information about the asterisk-commits mailing list