Browse code

optimize alt handling

Tomasz Kojm authored on 2009/09/10 05:50:24
Showing 1 changed files
... ...
@@ -668,7 +668,8 @@ int cli_ac_chklsig(const char *expr, const char *end, uint32_t *lsigcnt, unsigne
668 668
 		    if(alt->str[j] == b) {				\
669 669
 			match = 1;					\
670 670
 			break;						\
671
-		    }							\
671
+		    } else if(alt->str[j] > b)				\
672
+			break;						\
672 673
 		}							\
673 674
 	    } else {							\
674 675
 		while(alt) {						\
... ...
@@ -1156,6 +1157,11 @@ int cli_ac_scanbuff(const unsigned char *buffer, uint32_t length, const char **v
1156 1156
     return (mode & AC_SCAN_FT) ? type : CL_CLEAN;
1157 1157
 }
1158 1158
 
1159
+static int qcompare(const void *a, const void *b)
1160
+{
1161
+    return *(const uint32_t *)a - *(const uint32_t *)b;
1162
+}
1163
+
1159 1164
 /* FIXME: clean up the code */
1160 1165
 int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hexsig, uint32_t sigid, uint16_t parts, uint16_t partno, uint16_t rtype, uint16_t type, uint32_t mindist, uint32_t maxdist, const char *offset, const uint32_t *lsigid, unsigned int options)
1161 1166
 {
... ...
@@ -1388,6 +1394,8 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1388 1388
 
1389 1389
 		free(h);
1390 1390
 	    }
1391
+	    if(newalt->chmode)
1392
+		cli_qsort(newalt->str, newalt->num, sizeof(unsigned char), qcompare);
1391 1393
 
1392 1394
 	    if(error)
1393 1395
 		break;