Browse code

improve DB load time

git-svn: trunk@3853

Török Edvin authored on 2008/05/16 17:15:26
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Fri May 16 10:23:01 EEST 2008 (edwin)
2
+------------------------------------
3
+  * libclamav/readdb.c, str.c: improve DB load time
4
+
1 5
 Mon May 12 15:31:13 CEST 2008 (acab)
2 6
 ------------------------------------
3 7
   * clamd/server-th.c: minor fixes (bb#384)
... ...
@@ -911,9 +911,12 @@ static int cli_md5db_init(struct cl_engine **engine, unsigned int mode)
911 911
     else			    \
912 912
 	db = (*engine)->md5_fp;
913 913
 
914
+#define MD5_TOKENS 3
914 915
 static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo, unsigned int mode, unsigned int options, gzFile *gzs, unsigned int gzrsize, const char *dbname)
915 916
 {
916
-	char buffer[FILEBUFF], *pt;
917
+	const char *tokens[MD5_TOKENS];
918
+	char buffer[FILEBUFF];
919
+	const char *pt;
917 920
 	int ret = CL_SUCCESS;
918 921
 	unsigned int size_field = 1, md5_field = 0, line = 0, sigs = 0;
919 922
 	uint32_t size;
... ...
@@ -934,13 +937,15 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
934 934
 	line++;
935 935
 	cli_chomp(buffer);
936 936
 
937
+	cli_strtokenize(buffer, ':', MD5_TOKENS, tokens);
938
+
937 939
 	new = (struct cli_bm_patt *) cli_calloc(1, sizeof(struct cli_bm_patt));
938 940
 	if(!new) {
939 941
 	    ret = CL_EMEM;
940 942
 	    break;
941 943
 	}
942 944
 
943
-	if(!(pt = cli_strtok(buffer, md5_field, ":"))) {
945
+	if(!(pt = tokens[md5_field])) {
944 946
 	    free(new);
945 947
 	    ret = CL_EMALFDB;
946 948
 	    break;
... ...
@@ -948,24 +953,21 @@ static int cli_loadmd5(FILE *fs, struct cl_engine **engine, unsigned int *signo,
948 948
 
949 949
 	if(strlen(pt) != 32 || !(new->pattern = (unsigned char *) cli_hex2str(pt))) {
950 950
 	    cli_errmsg("cli_loadmd5: Malformed MD5 string at line %u\n", line);
951
-	    free(pt);
952 951
 	    free(new);
953 952
 	    ret = CL_EMALFDB;
954 953
 	    break;
955 954
 	}
956
-	free(pt);
957 955
 	new->length = 16;
958 956
 
959
-	if(!(pt = cli_strtok(buffer, size_field, ":"))) {
957
+	if(!(pt = tokens[size_field])) {
960 958
 	    free(new->pattern);
961 959
 	    free(new);
962 960
 	    ret = CL_EMALFDB;
963 961
 	    break;
964 962
 	}
965 963
 	size = atoi(pt);
966
-	free(pt);
967 964
 
968
-	if(!(new->virname = cli_strtok(buffer, 2, ":"))) {
965
+	if(!(new->virname = cli_strdup(tokens[2]))) {
969 966
 	    free(new->pattern);
970 967
 	    free(new);
971 968
 	    ret = CL_EMALFDB;
... ...
@@ -35,22 +35,28 @@
35 35
 #include "matcher.h"
36 36
 #include "cltypes.h"
37 37
 
38
-static int cli_hex2int(int c)
38
+static const int hex_chars[256] = {
39
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
40
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
41
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
42
+     0, 1, 2, 3,  4, 5, 6, 7,  8, 9,-1,-1, -1,-1,-1,-1,
43
+    -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
44
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
45
+    -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
46
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
47
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
48
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
49
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
50
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
51
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
52
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
53
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
54
+    -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
55
+};
56
+
57
+static inline int cli_hex2int(const char c)
39 58
 {
40
-	int l;
41
-
42
-    if(!isascii(c))
43
-    	return -1;
44
-
45
-    if(isdigit(c))
46
-	return c - '0';
47
-
48
-    l = tolower(c);
49
-    if((l >= 'a') && (l <= 'f'))
50
-	return l + 10 - 'a';
51
-
52
-    cli_errmsg("hex2int() translation problem (%d)\n", l);
53
-    return -1;
59
+	return hex_chars[(const unsigned char)c];
54 60
 }
55 61
 
56 62
 uint16_t *cli_hex2ui(const char *hex)