diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-11-02 02:14:19 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-11-02 02:14:19 +0000 |
commit | b31b9954cb0ec10441914ee90ea5fcd2d78a042f (patch) | |
tree | eeac98a2c85c4754587a4f095859c6c14b74a9e8 /apps/app_directed_pickup.c | |
parent | 1903743a14905de4bd3295bbceb46aa8d8b3f3f9 (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: http://svn.digium.com/svn/asterisk/trunk@153435 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_directed_pickup.c')
-rw-r--r-- | apps/app_directed_pickup.c | 17 |
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; |