From 5c181546172e13d4e4ff9a694b1585469096294d Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Thu, 29 Dec 2005 08:25:06 +0000 Subject: normalize a loop and avoid multiple strlen calls when completing voicemail users git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7668 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/app_voicemail.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index 9616afceb..6aa7bb5e3 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -5741,7 +5741,8 @@ static int handle_show_voicemail_zones(int fd, int argc, char *argv[]) static char *complete_show_voicemail_users(char *line, char *word, int pos, int state) { int which = 0; - struct ast_vm_user *vmu = users; + int wordlen; + struct ast_vm_user *vmu; char *context = ""; /* 0 - show; 1 - voicemail; 2 - users; 3 - for; 4 - */ @@ -5753,8 +5754,9 @@ static char *complete_show_voicemail_users(char *line, char *word, int pos, int else return NULL; } - while (vmu) { - if (!strncasecmp(word, vmu->context, strlen(word))) { + wordlen = strlen(word); + for (vmu = users; vmu; vmu = vmu->next) { + if (!strncasecmp(word, vmu->context, wordlen)) { if (context && strcmp(context, vmu->context)) { if (++which > state) { return strdup(vmu->context); @@ -5762,7 +5764,6 @@ static char *complete_show_voicemail_users(char *line, char *word, int pos, int context = vmu->context; } } - vmu = vmu->next; } return NULL; } -- cgit v1.2.3