[svn-commits] mmichelson: trunk r129734 - /trunk/apps/app_voicemail.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 10 15:33:14 CDT 2008


Author: mmichelson
Date: Thu Jul 10 15:33:13 2008
New Revision: 129734

URL: http://svn.digium.com/view/asterisk?view=rev&rev=129734
Log:
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.


Modified:
    trunk/apps/app_voicemail.c

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=129734&r1=129733&r2=129734
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Thu Jul 10 15:33:13 2008
@@ -420,7 +420,6 @@
 	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 @@
 	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 @@
 		}
 	}
 
-	/* 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 @@
 	int x = 0;
 #ifndef IMAP_STORAGE
 	int res = 0, nummsg;
+	char fn2[PATH_MAX];
 #endif
 
 	if (vms->lastmsg <= -1)
@@ -6267,9 +6262,9 @@
 			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 @@
 
 	/* 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 @@
 	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);




More information about the svn-commits mailing list