dect
/
asterisk
Archived
13
0
Fork 0

Removed the fn2 field from the vm_state structure.

fn2 was used in three functions. In every case, it was initialized
in the function it was used in. This meant there was no need
to have it in a malloc'd structure just taking up space. Furthermore
two of the functions it was used in were completely unnecessary since
fn2 was set to exactly the same value as the vm_state's fn string.

fn2 was a char array sized at PATH_MAX. On my system, PATH_MAX is 
4096. This equates to a 4K memory savings per vm_state allocated. 
Since there is a vm_state malloc'd for every voicemail user on 
the system, this could potentially add up nicely if there are lots 
of users. In addition, a vm_state is allocated on the stack each 
time a caller calls the VoiceMailMain application, meaning that 
there is a significant stack savings with this patch too.

Of course, a single vm_state struct still takes up approximately
20K on my system (when using IMAP storage. Without IMAP storage,
there would be about another 300 bytes fewer usage), even with 
this removal. Further optimizations are probably possible, 
but most likely not as easy as this one.



git-svn-id: http://svn.digium.com/svn/asterisk/trunk@129734 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
mmichelson 2008-07-10 20:33:13 +00:00
parent 4bc06f4114
commit b1b9a78505
1 changed files with 7 additions and 13 deletions

View File

@ -420,7 +420,6 @@ struct vm_state {
char curdir[PATH_MAX];
char vmbox[PATH_MAX];
char fn[PATH_MAX];
char fn2[PATH_MAX];
char intro[PATH_MAX];
int *deleted;
int *heard;
@ -5811,9 +5810,7 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
else if (vms->curmsg == vms->lastmsg)
res = wait_file2(chan, vms, "vm-last"); /* "last" */
/* Retrieve info from VM attribute file earlier, to get flag info */
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
snprintf(filename, sizeof(filename), "%s.txt", vms->fn2);
snprintf(filename, sizeof(filename), "%s.txt", vms->fn);
RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
msg_cfg = ast_config_load(filename, config_flags);
if (!msg_cfg) {
@ -5864,9 +5861,6 @@ static int play_message(struct ast_channel *chan, struct ast_vm_user *vmu, struc
}
}
/* Retrieve info from VM attribute file */
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
snprintf(filename, sizeof(filename), "%s.txt", vms->fn2);
RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
msg_cfg = ast_config_load(filename, config_flags);
if (!msg_cfg) {
@ -6249,6 +6243,7 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
int x = 0;
#ifndef IMAP_STORAGE
int res = 0, nummsg;
char fn2[PATH_MAX];
#endif
if (vms->lastmsg <= -1)
@ -6267,9 +6262,9 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
if (!EXISTS(vms->curdir, x, vms->fn, NULL))
break;
vms->curmsg++;
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
if (strcmp(vms->fn, vms->fn2)) {
RENAME(vms->curdir, x, vmu->mailbox,vmu->context, vms->curdir, vms->curmsg, vms->fn, vms->fn2);
make_file(fn2, sizeof(fn2), vms->curdir, vms->curmsg);
if (strcmp(vms->fn, fn2)) {
RENAME(vms->curdir, x, vmu->mailbox,vmu->context, vms->curdir, vms->curmsg, vms->fn, fn2);
}
} else if ((!strcasecmp(vms->curbox, "INBOX") || !strcasecmp(vms->curbox, "Urgent")) && vms->heard[x] && ast_test_flag(vmu, VM_MOVEHEARD) && !vms->deleted[x]) {
/* Move to old folder before deleting */
@ -8043,6 +8038,7 @@ static int vm_execmain(struct ast_channel *chan, void *data)
/* Add the vm_state to the active list and keep it active */
memset(&vms, 0, sizeof(vms));
vms.lastmsg = -1;
memset(&vmus, 0, sizeof(vmus));
@ -10297,9 +10293,7 @@ static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, s
make_file(vms->fn, sizeof(vms->fn), vms->curdir, msg);
/* Retrieve info from VM attribute file */
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
snprintf(filename,sizeof(filename), "%s.txt", vms->fn2);
snprintf(filename,sizeof(filename), "%s.txt", vms->fn);
RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
msg_cfg = ast_config_load(filename, config_flags);
DISPOSE(vms->curdir, vms->curmsg);