From 7b1b9f53ef47abd82c6faba12f4adcf721e622da Mon Sep 17 00:00:00 2001 From: kpfleming Date: Mon, 6 Jun 2005 02:29:18 +0000 Subject: more efficient (and understandable) ast_channel_walk_locked, and vastly more efficient ast_channel_by_name_locked (bug #4265) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5853 f38db490-d61c-443f-a65b-d21fe96a405b --- app.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'app.c') diff --git a/app.c b/app.c index b61ff55ae..9f4267f34 100755 --- a/app.c +++ b/app.c @@ -1013,22 +1013,20 @@ int ast_app_group_get_count(char *group, char *category) int count = 0; char *test; char cat[80] = ""; + char *s; - if (category && !ast_strlen_zero(category)) { - ast_copy_string(cat, category, sizeof(cat)); - } else { - ast_copy_string(cat, GROUP_CATEGORY_PREFIX, sizeof(cat)); - } + if (group == NULL || ast_strlen_zero(group)) + return 0; - if (group && !ast_strlen_zero(group)) { - chan = ast_channel_walk_locked(NULL); - while(chan) { - test = pbx_builtin_getvar_helper(chan, cat); - if (test && !strcasecmp(test, group)) - count++; - ast_mutex_unlock(&chan->lock); - chan = ast_channel_walk_locked(chan); - } + s = (category && !ast_strlen_zero(category)) ? category : GROUP_CATEGORY_PREFIX; + ast_copy_string(cat, s, sizeof(cat)); + + chan = NULL; + while ((chan = ast_channel_walk_locked(chan)) != NULL) { + test = pbx_builtin_getvar_helper(chan, cat); + if (test && !strcasecmp(test, group)) + count++; + ast_mutex_unlock(&chan->lock); } return count; @@ -1041,6 +1039,7 @@ int ast_app_group_match_get_count(char *groupmatch, char *category) int count = 0; char *test; char cat[80] = ""; + char *s; if (!groupmatch || ast_strlen_zero(groupmatch)) return 0; @@ -1049,14 +1048,11 @@ int ast_app_group_match_get_count(char *groupmatch, char *category) if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) return 0; - if (category && !ast_strlen_zero(category)) { - ast_copy_string(cat, category, sizeof(cat)); - } else { - ast_copy_string(cat, GROUP_CATEGORY_PREFIX, sizeof(cat)); - } + s = (category && !ast_strlen_zero(category)) ? category : GROUP_CATEGORY_PREFIX; + ast_copy_string(cat, s, sizeof(cat)); - chan = ast_channel_walk_locked(NULL); - while(chan) { + chan = NULL; + while ((chan = ast_channel_walk_locked(chan)) != NULL) { test = pbx_builtin_getvar_helper(chan, cat); if (test && !regexec(®exbuf, test, 0, NULL, 0)) count++; -- cgit v1.2.3