aboutsummaryrefslogtreecommitdiffstats
path: root/app.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-06-06 02:29:18 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-06-06 02:29:18 +0000
commit7b1b9f53ef47abd82c6faba12f4adcf721e622da (patch)
treebe967c9ab3099202d13219196b5f17284a939e78 /app.c
parentd39208dd35ce0ead92bf6a4b21361f3d13759589 (diff)
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
Diffstat (limited to 'app.c')
-rwxr-xr-xapp.c38
1 files changed, 17 insertions, 21 deletions
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(&regexbuf, 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(&regexbuf, test, 0, NULL, 0))
count++;