Browse code

minor optimization

git-svn: trunk@2030

Tomasz Kojm authored on 2006/06/18 04:31:45
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sat Jun 17 21:17:20 CEST 2006 (tk)
2
+----------------------------------
3
+  * libclamav/matcher-bm.c: minor optimization patch (~7% speed up) from
4
+			    Christophe Poujol <christophe.poujol*atosorigin.com>
5
+
1 6
 Fri Jun 16 16:03:45 CEST 2006 (tk)
2 7
 ----------------------------------
3 8
   * libclamav/readdb.c: fix small memory leak in cl_free()
... ...
@@ -132,6 +132,7 @@ void cli_bm_free(struct cli_matcher *root)
132 132
 int cli_bm_scanbuff(const char *buffer, unsigned int length, const char **virname, const struct cli_matcher *root, unsigned long int offset, unsigned short ftype, int fd)
133 133
 {
134 134
 	unsigned int i, j, shift, off, found = 0;
135
+	int idxtest;
135 136
 	uint16_t idx;
136 137
 	struct cli_bm_patt *p;
137 138
 	const char *bp;
... ...
@@ -168,6 +169,14 @@ int cli_bm_scanbuff(const char *buffer, unsigned int length, const char **virnam
168 168
 		}
169 169
 #endif
170 170
 
171
+		idxtest = MIN (p->length, length - off ) - 1;
172
+		if(idxtest >= 0) {
173
+		    if(bp[idxtest] != p->pattern[idxtest]) {
174
+			p = p->next;
175
+			continue;
176
+		    }
177
+		}
178
+
171 179
 		found = 1;
172 180
 		for(j = 0; j < p->length && off < length; j++, off++) {
173 181
 		    if(bp[j] != p->pattern[j]) {