summaryrefslogtreecommitdiff
path: root/apps/app_directed_pickup.c
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2008-11-02 02:14:19 +0000
committerRussell Bryant <russell@russellbryant.com>2008-11-02 02:14:19 +0000
commitad533bc62b5f57644b6cdf5c294252d8dc2c15b4 (patch)
treeeeac98a2c85c4754587a4f095859c6c14b74a9e8 /apps/app_directed_pickup.c
parent981c2d03b69674f6ccd4b21d255880c68fb1bc42 (diff)
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
Diffstat (limited to 'apps/app_directed_pickup.c')
-rw-r--r--apps/app_directed_pickup.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/apps/app_directed_pickup.c b/apps/app_directed_pickup.c
index 5f88df85d..2a07d2ebb 100644
--- a/apps/app_directed_pickup.c
+++ b/apps/app_directed_pickup.c
@@ -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;