Faster load of the content file.

This commit is contained in:
Andrea Mazzoleni 2011-06-22 20:55:54 +02:00
parent 132ccef591
commit 7f400289b8
4 changed files with 35 additions and 27 deletions

56
util.c
View file

@ -125,40 +125,48 @@ void strenchex(char* str, const void* void_data, unsigned data_len)
}
}
static unsigned strdecset[256] =
{
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
char* strdechex(void* void_data, unsigned data_len, char* str)
{
unsigned char* data = void_data;
unsigned i;
for(i=0;i<data_len;++i) {
char c0;
char c1;
unsigned char b0;
unsigned char b1;
unsigned b0;
unsigned b1;
unsigned b;
c0 = *str;
if (c0 >= '0' && c0 <= '9')
b0 = c0 - '0';
else if (c0 >= 'a' && c0 <= 'f')
b0 = c0 - 'a' + 10;
else if (c0 >= 'A' && c0 <= 'F')
b0 = c0 - 'A' + 10;
else
b0 = strdecset[(unsigned char)str[0]];
b1 = strdecset[(unsigned char)str[1]];
b = (b0 << 4) | b1;
if (b > 0xFF)
return str;
++str;
c1 = *str;
if (c1 >= '0' && c1 <= '9')
b1 = c1 - '0';
else if (c1 >= 'a' && c1 <= 'f')
b1 = c1 - 'a' + 10;
else if (c1 >= 'A' && c1 <= 'F')
b1 = c1 - 'A' + 10;
else
return str;
++str;
data[0] = b;
data[i] = (b0 << 4) | b1;
data += 1;
str += 2;
}
return 0;