@cire - I think you may be misunderstanding my question. Not your fault as I am probably being very unclear as to what I'm trying to accomplish here, and the fact that I haven't provided any code isn't helping anything...
So, to be clear, I have determined that sscanf is doing it's job too slowly. All I need sscanf to do is take in some buffer, read an ASCII value and convert it to hex for me. So I wrote a quicker conversion function (but it's shitty).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
inline signed short ConvertAsciiHexCharToInt( char byAsciiChar )
{
// 0 - 9
// A - F
// a - f
char byRetValue = -1;
if( byAsciiChar >= '0' && byAsciiChar <= '9' )
{
byRetValue = byAsciiChar - '0';
}
else if( byAsciiChar >= 'A' && byAsciiChar <= 'F' )
{
byRetValue = byAsciiChar - 'A' + 0x0A;
}
else if( byAsciiChar >= 'a' && byAsciiChar <= 'f' )
{
byRetValue = byAsciiChar - 'a' + 0x0A;
}
return byRetValue;
}
inline signed short ConvertAsciiHexToInt( char* pbyBuffer )
{
signed short wRetValue = -1;
signed short wUpper = ConvertAsciiHexCharToInt( pbyBuffer[0] );
signed short wLower = ConvertAsciiHexCharToInt( pbyBuffer[1] );
// This checks if either sign bit is set (negative) most efficiently...
if( wUpper | wLower > 0)
{
// MAKEWORD is a macro that will shift these suckers over to high byte and low byte
wRetValue = MAKEWORD( wUpper , wLower );
}
return wRetValue;
}
|
Now, the code I'm trying to refactor would do something like this previously:
1 2
|
unsigned int dwRecordLength = 0;
sscanf( (const char*)( pbyBuffer + dwPos ), %02X, &dwRecordLength );
|
I'm trying to replace that with this:
1 2
|
// Get the byte count
char byByteCount = ConvertAsciiHexToInt( pbyBuffer+dwPos );
|
Remember these are just code snippets, there is a total of about 3 or 4 of these calls all siting in a while( not done parsing file ) loop. For a file about 350KB the first code would take about 6 seconds, with my improvements that's down to a fraction of a second, but still somewhat significant (about 100-350ms or so...)
Okay now hopefully you see why I don't want to use sscanf.
NOW BACK TO MY ORIGINAL QUESTION!!!!
I need to parse Intel Hex Records, that's what these files are
http://en.wikipedia.org/wiki/Intel_HEX
http://www.lucidtechnologies.info/intel.htm
Does anyone know of any good libraries for parsing this stuff? Anyone ever done this before and have any suggestions/tips?