This is a simple example of the basic code refactoring exercise I am performing with DCDFLIB. All of these code examples were examined with reflector after compiling to determine a "best path" to follow.
C++ code converted from FORTRAN:
if(!(which < 1 || which > 4)) goto S30;
if(!(which < 1)) goto S10;
bound = 1.0e0;
goto S20;
S10:
bound = 4.0e0;
S20:
status = -1;
return;
S30:
Re-factored code in managed c++:
if (which < 1)
{
bound = 1.0e0;
status = -1;
return;
}
else if (which > 4)
{
bound = 4.0e0;
status = -1;
return;
}
I looked at re-factoring using more of the existing code, but I found the compiler could do a better optimizing job using the first code snippet.
Re-factoring code path I decided not to use:
if ((which < 1) || (which > 4))
{
if (which < 1)
bound = 1.0e0;
else
bound = 4.0e0;
status = -1;
return;
}
If I include just a bit more code when attempting the re-factor operation, the following re-factor code is possible. It did not seem to offer any advantages when the IL assembly was examined using reflector.
double bound = 0.0;
if (which < 1)
bound = 1.0;
else if (which > 4)
bound = 4.0;
if (0.0 != bound)
{
status = -1;
return;
}