839 |
|
|
840 |
/* If the switch type can fit in a 32-bit integer, and the |
/* If the switch type can fit in a 32-bit integer, and the |
841 |
cases fill up at least 80% of the range, then use an |
cases fill up at least 80% of the range, then use an |
842 |
indexed table for the switch */ |
indexed table for the switch. But the calculation is prone |
843 |
|
to overflow, hence the upper limit check. */ |
844 |
type = ILTypeToMachineType(switchType); |
type = ILTypeToMachineType(switchType); |
845 |
switch(type) |
switch(type) |
846 |
{ |
{ |
853 |
{ |
{ |
854 |
range = (unsigned long)(values[numValues - 1].value.un.i4Value - |
range = (unsigned long)(values[numValues - 1].value.un.i4Value - |
855 |
values[0].value.un.i4Value); |
values[0].value.un.i4Value); |
856 |
if(((range * 80) / 100) <= numValues) |
if(((range * 4) / 5) <= numValues && range < 0x1fffffff) |
857 |
{ |
{ |
858 |
return ILSwitchTableType_Indexed; |
return ILSwitchTableType_Indexed; |
859 |
} |
} |
869 |
range = (unsigned long) |
range = (unsigned long) |
870 |
(((ILUInt32)(values[numValues - 1].value.un.i4Value)) - |
(((ILUInt32)(values[numValues - 1].value.un.i4Value)) - |
871 |
((ILUInt32)(values[0].value.un.i4Value))); |
((ILUInt32)(values[0].value.un.i4Value))); |
872 |
if(((range * 80) / 100) <= numValues) |
if(((range * 4) / 5) <= numValues && range < 0x3fffffff) |
873 |
{ |
{ |
874 |
return ILSwitchTableType_Indexed; |
return ILSwitchTableType_Indexed; |
875 |
} |
} |