Skip to content
Snippets Groups Projects
Commit ad533bc6 authored by Russell Bryant's avatar Russell Bryant
Browse files

Instead of doing a couple of strlen() calls each iteration of the loop, only do it once

at the beginning of the function


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@153435 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 981c2d03
No related branches found
No related tags found
No related merge requests found
......@@ -122,10 +122,16 @@ static int can_pickup(struct ast_channel *chan)
}
/*! \brief Helper Function to walk through ALL channels checking NAME and STATE */
static struct ast_channel *my_ast_get_channel_by_name_locked(char *channame)
static struct ast_channel *my_ast_get_channel_by_name_locked(const char *channame)
{
struct ast_channel *chan;
char *chkchan = alloca(strlen(channame) + 2);
char *chkchan;
size_t channame_len, chkchan_len;
channame_len = strlen(channame);
chkchan_len = channame_len + 2;
chkchan = alloca(chkchan_len);
/* need to append a '-' for the comparison so we check full channel name,
* i.e SIP/hgc- , use a temporary variable so original stays the same for
......@@ -134,11 +140,12 @@ static struct ast_channel *my_ast_get_channel_by_name_locked(char *channame)
strcpy(chkchan, channame);
strcat(chkchan, "-");
for (chan = ast_walk_channel_by_name_prefix_locked(NULL, channame, strlen(channame));
for (chan = ast_walk_channel_by_name_prefix_locked(NULL, channame, channame_len);
chan;
chan = ast_walk_channel_by_name_prefix_locked(chan, channame, strlen(channame))) {
if (!strncasecmp(chan->name, chkchan, strlen(chkchan)) && can_pickup(chan))
chan = ast_walk_channel_by_name_prefix_locked(chan, channame, channame_len)) {
if (!strncasecmp(chan->name, chkchan, chkchan_len) && can_pickup(chan)) {
return chan;
}
ast_channel_unlock(chan);
}
return NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment