Browse code

Don't copy if the decoded == the encoded

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

Nigel Horne authored on 2004/09/29 03:42:30
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Sep 28 19:41:39 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav:		Some small speed and size optimisations in MIME decoding
4
+
1 5
 Tue Sep 28 15:46:18 BST 2004 (njh)
2 6
 ---------------------------------
3 7
   * contrib/clamavmon:	No longer multithreaded
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.91  2004/09/28 18:39:48  nigelhorne
21
+ * Don't copy if the decoded == the encoded
22
+ *
20 23
  * Revision 1.90  2004/09/22 16:24:22  nigelhorne
21 24
  * Fix error return
22 25
  *
... ...
@@ -267,7 +270,7 @@
267 267
  * uuencodebegin() no longer static
268 268
  *
269 269
  */
270
-static	char	const	rcsid[] = "$Id: message.c,v 1.90 2004/09/22 16:24:22 nigelhorne Exp $";
270
+static	char	const	rcsid[] = "$Id: message.c,v 1.91 2004/09/28 18:39:48 nigelhorne Exp $";
271 271
 
272 272
 #if HAVE_CONFIG_H
273 273
 #include "clamav-config.h"
... ...
@@ -1703,7 +1706,20 @@ messageToText(message *m)
1703 1703
 			if(last == NULL)
1704 1704
 				break;
1705 1705
 
1706
-			last->t_line = ((data[0] != '\n') && data[0]) ? lineCreate((char *)data) : NULL;
1706
+			/*
1707
+			 * If the decoded line is the same as the encoded
1708
+			 * there's no need to take a copy, just link it.
1709
+			 * Note that the comparison is done without the
1710
+			 * trailing newline that the decoding routine may have
1711
+			 * added - that's why there's a strncmp rather than a
1712
+			 * strcmp - that'd be bad for MIME decoders, but is OK
1713
+			 * for AV software
1714
+			 */
1715
+			if(line && (strncmp(data, line, strlen(line)) == 0)) {
1716
+				cli_dbgmsg("messageToText: decoded line is the same(%s)\n", data);
1717
+				last->t_line = lineLink(t_line->t_line);
1718
+			} else
1719
+				last->t_line = ((data[0] != '\n') && data[0]) ? lineCreate((char *)data) : NULL;
1707 1720
 
1708 1721
 			if(line && enctype == BASE64)
1709 1722
 				if(strchr(line, '='))