diff options
author | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2012-04-03 01:49:27 +0000 |
---|---|---|
committer | Martin Mathieson <martin.r.mathieson@googlemail.com> | 2012-04-03 01:49:27 +0000 |
commit | f0798dabd12a862bb3595aef174d40610eabde5e (patch) | |
tree | b8fa4c0062dce81fc7170f3114eb7fc1a64f3d93 /wiretap | |
parent | b4f42921bbe9f2e7c7f06d61b41bad1aeafcd8a3 (diff) | |
download | wireshark-f0798dabd12a862bb3595aef174d40610eabde5e.tar.gz wireshark-f0798dabd12a862bb3595aef174d40610eabde5e.tar.bz2 wireshark-f0798dabd12a862bb3595aef174d40610eabde5e.zip |
Set up table to help with ascii-hex -> hex conversion in advance to
avoid testing static for every conversion.
svn path=/trunk/; revision=41900
Diffstat (limited to 'wiretap')
-rw-r--r-- | wiretap/catapult_dct2000.c | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/wiretap/catapult_dct2000.c b/wiretap/catapult_dct2000.c index 041ee83275..75bdff5100 100644 --- a/wiretap/catapult_dct2000.c +++ b/wiretap/catapult_dct2000.c @@ -141,6 +141,7 @@ static int write_stub_header(guint8 *frame_buffer, char *timestamp_string, gchar *protocol_name, gchar *variant_name, gchar *outhdr_name); static guint8 hex_from_char(gchar c); +static void prepare_hex_byte_from_chars_table(void); static guint8 hex_byte_from_chars(gchar *c); static gchar char_from_hex(guint8 hex); @@ -178,6 +179,7 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info _U_) gint firstline_length = 0; dct2000_file_externals_t *file_externals; static gchar linebuff[MAX_LINE_LENGTH]; + static gboolean hex_byte_table_values_set = FALSE; /* Clear errno before reading from the file */ errno = 0; @@ -199,6 +201,11 @@ catapult_dct2000_open(wtap *wth, int *err, gchar **err_info _U_) return 0; } + /* Make sure table is ready for use */ + if (!hex_byte_table_values_set) { + prepare_hex_byte_from_chars_table(); + hex_byte_table_values_set = TRUE; + } /*********************************************************************/ /* Need entry in file_externals table */ @@ -1423,29 +1430,30 @@ hex_from_char(gchar c) return 0xff; } -/* Extract and return a byte value from 2 ascii hex chars, starting from the given pointer */ -static guint8 -hex_byte_from_chars(gchar *c) + + +/* Table allowing fast lookup from a pair of ascii hex characters to a guint8 */ +static guint8 s_tableValues[255][255]; + +/* Prepare table values so ready so don't need to check inside hex_byte_from_chars() */ +static void prepare_hex_byte_from_chars_table(void) { - static guchar hex_char_array[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f' }; - - /* Populate lookup table first time */ - static guint8 tableValues[255][255]; - static gint tableSet = FALSE; - if (!tableSet) { - gint i, j; - for (i=0; i < 16; i++) { - for (j=0; j < 16; j++) { - tableValues[hex_char_array[i]][hex_char_array[j]] = i*16 + j; - } - } + guchar hex_char_array[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + 'a', 'b', 'c', 'd', 'e', 'f' }; - tableSet = TRUE; + gint i, j; + for (i=0; i < 16; i++) { + for (j=0; j < 16; j++) { + s_tableValues[hex_char_array[i]][hex_char_array[j]] = i*16 + j; + } } +} +/* Extract and return a byte value from 2 ascii hex chars, starting from the given pointer */ +static guint8 hex_byte_from_chars(gchar *c) +{ /* Return value from quick table lookup */ - return tableValues[(unsigned char)c[0]][(unsigned char)c[1]]; + return s_tableValues[(unsigned char)c[0]][(unsigned char)c[1]]; } |