From a8af7fec323ca1a7796fc9587796095fe3dcc954 Mon Sep 17 00:00:00 2001 From: marha Date: Tue, 2 Nov 2010 17:57:08 +0000 Subject: Use table lookup again for HexTable --- libX11/src/RdBitF.c | 55 ++++++++++++++++------------------------------- libX11/src/genhextable.py | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 36 deletions(-) create mode 100644 libX11/src/genhextable.py (limited to 'libX11') diff --git a/libX11/src/RdBitF.c b/libX11/src/RdBitF.c index 07b47494b..e9a509c55 100644 --- a/libX11/src/RdBitF.c +++ b/libX11/src/RdBitF.c @@ -54,41 +54,24 @@ from The Open Group. #define MAX_SIZE 255 /* shared data for the image read/parse logic */ -/* -static const short hexTable[256] = { - ['0'] = 0, ['1'] = 1, - ['2'] = 2, ['3'] = 3, - ['4'] = 4, ['5'] = 5, - ['6'] = 6, ['7'] = 7, - ['8'] = 8, ['9'] = 9, - ['A'] = 10, ['B'] = 11, - ['C'] = 12, ['D'] = 13, - ['E'] = 14, ['F'] = 15, - ['a'] = 10, ['b'] = 11, - ['c'] = 12, ['d'] = 13, - ['e'] = 14, ['f'] = 15, - - [' '] = -1, [','] = -1, - ['}'] = -1, ['\n'] = -1, - ['\t'] = -1 +static const signed char hexTable[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0 + , 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0 + , 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -*/ -short hexTable(unsigned char Char) -{ - if (Char<'0') - return -1; - if (Char<='9') - return Char-'0'; - if (Char<'A') - return -1; - if (Char<='F') - return Char-'A'+10; - if (Char<'a') - return -1; - if (Char<='f') - return Char-'a'+10; - return -1; -} /* * read next hex value in the input stream, return -1 if EOF @@ -114,9 +97,9 @@ NextInt ( /* trim high bits, check type and accumulate */ ch &= 0xff; if (isascii(ch) && isxdigit(ch)) { - value = (value << 4) + hexTable(ch); + value = (value << 4) + hexTable[ch]; gotone++; - } else if ((hexTable(ch)) < 0 && gotone) + } else if ((hexTable[ch]) < 0 && gotone) done++; } } diff --git a/libX11/src/genhextable.py b/libX11/src/genhextable.py new file mode 100644 index 000000000..2a45a9e83 --- /dev/null +++ b/libX11/src/genhextable.py @@ -0,0 +1,39 @@ +import sys + +HexTable={ + '0' : 0, '1' : 1, + '2' : 2, '3' : 3, + '4' : 4, '5' : 5, + '6' : 6, '7' : 7, + '8' : 8, '9' : 9, + 'A' : 10, 'B' : 11, + 'C' : 12, 'D' : 13, + 'E' : 14, 'F' : 15, + 'a' : 10, 'b' : 11, + 'c' : 12, 'd' : 13, + 'e' : 14, 'f' : 15, + + ' ' : -1, ',' : -1, + '}' : -1, '\n' : -1, + '\t' : -1 +} + +OutHexTable=[0]*256 + +for Char,Val in HexTable.iteritems(): + OutHexTable[ord(Char)]=Val + +print "static const short hexTable[256] = {" +i=0 +for Item in OutHexTable: + if i==0: + PreFix=" " + elif i%16 == 0: + PreFix="\n ," + else: + PreFix=", " + i+=1 + Val="%d"%Item + if len(Val)==1: Val = " "+Val + sys.stdout.write("%s%s"%(PreFix,Val)) +print "\n};" \ No newline at end of file -- cgit v1.2.3