[asterisk-commits] trunk - r7659 in /trunk/channels: chan_iax2.c iax2-provision.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Dec 27 13:48:45 CST 2005


Author: russell
Date: Tue Dec 27 13:48:44 2005
New Revision: 7659

URL: http://svn.digium.com/view/asterisk?rev=7659&view=rev
Log:
avoid unneeded calls to strlen in iax2 completion functions

Modified:
    trunk/channels/chan_iax2.c
    trunk/channels/iax2-provision.c

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=7659&r1=7658&r2=7659&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Tue Dec 27 13:48:44 2005
@@ -1975,13 +1975,14 @@
 	int which = 0;
 	struct iax2_peer *p;
 	char *res = NULL;
+	int wordlen = strlen(word);
 
 	/* 0 - iax2; 1 - show; 2 - peer; 3 - <peername> */
-	if(pos == 3) {
+	if (pos == 3) {
 		ast_mutex_lock(&peerl.lock);
-		for(p = peerl.peers ; p ; p = p->next) {
-			if(!strncasecmp(p->name, word, strlen(word))) {
-				if(++which > state) {
+		for (p = peerl.peers ; p ; p = p->next) {
+			if (!strncasecmp(p->name, word, wordlen)) {
+				if (++which > state) {
 					res = strdup(p->name);
 					break;
 				}

Modified: trunk/channels/iax2-provision.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/iax2-provision.c?rev=7659&r1=7658&r2=7659&view=diff
==============================================================================
--- trunk/channels/iax2-provision.c (original)
+++ trunk/channels/iax2-provision.c Tue Dec 27 13:48:44 2005
@@ -156,21 +156,20 @@
 {
 	struct iax_template *c;
 	int which=0;
-	char *ret;
+	char *ret = NULL;
+	int wordlen = strlen(word);
+
 	ast_mutex_lock(&provlock);
-	c = templates;
-	while(c) {
-		if (!strncasecmp(word, c->name, strlen(word))) {
-			if (++which > state)
+	for (c = templates; c; c = c->next) {
+		if (!strncasecmp(word, c->name, wordlen)) {
+			if (++which > state) {
+				ret = strdup(c->name);
 				break;
-		}
-		c = c->next;
-	}
-	if (c) {
-		ret = strdup(c->name);
-	} else
-		ret = NULL;
+			}
+		}
+	}
 	ast_mutex_unlock(&provlock);
+	
 	return ret;
 }
 



More information about the asterisk-commits mailing list