Browse code

Implemented a couple of small speed improvements

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@387 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/03/10 14:37:46
Showing 2 changed files
... ...
@@ -1,3 +1,10 @@
1
+Wed Mar 10 05:43:34 GMT 2004 (njh)
2
+----------------------------------
3
+  * libclamav/message.c:	Implemented a couple of small speed ups:
4
+  	1) Only save arguments that we're going to retrieve
5
+	2) No need to store \n in messageToText fast copy mode, which allows
6
+		an sprintf to be removed (Dirk Mueller <dmuell@gmx.net>)
7
+
1 8
 Wed Mar 10 01:35:40 CET 2004 (tk)
2 9
 ---------------------------------
3 10
   * libclamav: unrarlib: cleanup (Dirk Mueller <dmuell*gmx.net>)
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.37  2004/03/10 05:35:03  nigelhorne
21
+ * Implemented a couple of small speed improvements
22
+ *
20 23
  * Revision 1.36  2004/03/07 15:11:48  nigelhorne
21 24
  * Fixed minor typo in bounce message
22 25
  *
... ...
@@ -105,7 +108,7 @@
105 105
  * uuencodebegin() no longer static
106 106
  *
107 107
  */
108
-static	char	const	rcsid[] = "$Id: message.c,v 1.36 2004/03/07 15:11:48 nigelhorne Exp $";
108
+static	char	const	rcsid[] = "$Id: message.c,v 1.37 2004/03/10 05:35:03 nigelhorne Exp $";
109 109
 
110 110
 #if HAVE_CONFIG_H
111 111
 #include "clamav-config.h"
... ...
@@ -123,11 +126,6 @@ static	char	const	rcsid[] = "$Id: message.c,v 1.36 2004/03/07 15:11:48 nigelhorn
123 123
 
124 124
 #if	C_DARWIN
125 125
 #include <sys/types.h>
126
-#include <sys/malloc.h>
127
-#else
128
-#ifdef HAVE_MALLOC_H /* tk: FreeBSD-CURRENT doesn't support malloc.h */
129
-#include <malloc.h>
130
-#endif
131 126
 #endif
132 127
 #include <stdlib.h>
133 128
 #include <string.h>
... ...
@@ -367,6 +365,21 @@ messageAddArgument(message *m, const char *arg)
367 367
 		/* Empty argument? Probably a broken mail client... */
368 368
 		return;
369 369
 
370
+	/*
371
+	 * These are the only arguments we're interested in.
372
+	 * Do 'fgrep messageFindArgument *.c' if you don't believe me!
373
+	 * It's probably not good doing this since each time a new
374
+	 * messageFindArgument is added I need to remember to look here,
375
+	 * but it can save a lot of memory...
376
+	 */
377
+	if((strncasecmp(arg, "name", 4) != 0) &&
378
+	   (strncasecmp(arg, "filename", 8) != 0) &&
379
+	   (strncasecmp(arg, "boundary", 8) != 0) &&
380
+	   (strncasecmp(arg, "type", 4) != 0)) {
381
+	   	cli_dbgmsg("Discarding unwanted argument '%s'\n", arg);
382
+		return;
383
+	}
384
+
370 385
 	cli_dbgmsg("Add argument '%s'\n", arg);
371 386
 
372 387
 	for(offset = 0; offset < m->numberOfArguments; offset++)
... ...
@@ -647,8 +660,6 @@ messageAddLine(message *m, const char *line)
647 647
 		m->body_last = m->body_last->t_next;
648 648
 	}
649 649
 
650
-	assert(m->body_last != NULL);
651
-
652 650
 	m->body_last->t_next = NULL;
653 651
 
654 652
 	m->body_last->t_text = strdup((line) ? line : "");
... ...
@@ -1018,7 +1029,7 @@ messageToText(const message *m)
1018 1018
 		 * Fast copy
1019 1019
 		 */
1020 1020
 		for(t_line = messageGetBody(m); t_line; t_line = t_line->t_next) {
1021
-			const char *line;
1021
+			/*const char *line;*/
1022 1022
 
1023 1023
 			if(first == NULL)
1024 1024
 				first = last = cli_malloc(sizeof(text));
... ...
@@ -1027,15 +1038,17 @@ messageToText(const message *m)
1027 1027
 				last = last->t_next;
1028 1028
 			}
1029 1029
 
1030
-			assert(last != NULL);
1031
-
1032
-			line = t_line->t_text;
1030
+			/*line = t_line->t_text;
1033 1031
 
1034 1032
 			last->t_text = cli_malloc(strlen(line) + 2);
1035 1033
 
1036 1034
 			assert(last->t_text != NULL);
1037 1035
 
1038
-			sprintf(last->t_text, "%s\n", line);
1036
+			sprintf(last->t_text, "%s\n", line);*/
1037
+			if((last->t_text = strdup(t_line->t_text)) == NULL) {
1038
+				textDestroy(first);
1039
+				return NULL;
1040
+			}
1039 1041
 		}
1040 1042
 	else {
1041 1043
 		if(messageGetEncoding(m) == UUENCODE) {
... ...
@@ -1074,7 +1087,6 @@ messageToText(const message *m)
1074 1074
 				last->t_next = cli_malloc(sizeof(text));
1075 1075
 				last = last->t_next;
1076 1076
 			}
1077
-			assert(last != NULL);
1078 1077
 
1079 1078
 			last->t_text = strdup((char *)data);
1080 1079
 			assert(last->t_text != NULL);
... ...
@@ -1146,6 +1158,9 @@ bounceBegin(const message *m)
1146 1146
 	if(bounceMessages == NULL) {
1147 1147
 		const char **bounce;
1148 1148
 
1149
+		/*
1150
+		 * TODO: mutex this in a multi-threaded environment
1151
+		 */
1149 1152
 		bounceMessages = tableCreate();
1150 1153
 
1151 1154
 		for(bounce = bounces; *bounce; bounce++)