#549 changed switch/case table to cascaded range checks

This commit is contained in:
jmarlin 2015-07-28 17:41:53 -04:00
parent 9f52cfd348
commit 8e75ec2ce7
1 changed files with 27 additions and 35 deletions

View File

@ -12,7 +12,7 @@
DWORD CMemoryLabel::AsciiToHex (char * HexValue) DWORD CMemoryLabel::AsciiToHex (char * HexValue)
{ {
DWORD Count, Finish, Value = 0; DWORD Count, Finish, Current, Value = 0;
Finish = strlen(HexValue); Finish = strlen(HexValue);
if (Finish > 8 ) if (Finish > 8 )
@ -23,35 +23,27 @@ DWORD CMemoryLabel::AsciiToHex (char * HexValue)
for (Count = 0; Count < Finish; Count++) for (Count = 0; Count < Finish; Count++)
{ {
Value = (Value << 4); Value = (Value << 4);
switch ( HexValue[Count] ) Current = HexValue[Count];
if(Current >= '0' && Current <= '9')
{
Value += Current - '0';
}
else
{
if(Current < 'A')
Current += 'A'
if (Current >= 'A' && Current <= 'F')
{
Value += Current + 10 - 'A';
}
else
{ {
case '0': break;
case '1': Value += 1; break;
case '2': Value += 2; break;
case '3': Value += 3; break;
case '4': Value += 4; break;
case '5': Value += 5; break;
case '6': Value += 6; break;
case '7': Value += 7; break;
case '8': Value += 8; break;
case '9': Value += 9; break;
case 'A': Value += 10; break;
case 'a': Value += 10; break;
case 'B': Value += 11; break;
case 'b': Value += 11; break;
case 'C': Value += 12; break;
case 'c': Value += 12; break;
case 'D': Value += 13; break;
case 'd': Value += 13; break;
case 'E': Value += 14; break;
case 'e': Value += 14; break;
case 'F': Value += 15; break;
case 'f': Value += 15; break;
default:
Value = (Value >> 4); Value = (Value >> 4);
Count = Finish; Count = Finish;
} }
} }
}
return Value; return Value;
} }