normalize a loop and avoid multiple strlen calls when completing voicemail users
authorRussell Bryant <russell@russellbryant.com>
Thu, 29 Dec 2005 08:25:06 +0000 (08:25 +0000)
committerRussell Bryant <russell@russellbryant.com>
Thu, 29 Dec 2005 08:25:06 +0000 (08:25 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7668 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c

index 9616afc..6aa7bb5 100644 (file)
@@ -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 - <context> */
@@ -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;
 }