REFACTOR: Invert 'if' statement to reduce nesting.

This commit is contained in:
2017-12-21 06:06:19 +00:00
parent fae5e8a4c8
commit 37130d7599
3 changed files with 334 additions and 350 deletions

View File

@@ -124,11 +124,11 @@ namespace DiscImageChef.Checksums
{
EccInit();
if(channel[0x000] == 0x00 && // sync (12 bytes)
channel[0x001] == 0xFF && channel[0x002] == 0xFF && channel[0x003] == 0xFF && channel[0x004] == 0xFF &&
channel[0x005] == 0xFF && channel[0x006] == 0xFF && channel[0x007] == 0xFF && channel[0x008] == 0xFF &&
channel[0x009] == 0xFF && channel[0x00A] == 0xFF && channel[0x00B] == 0x00)
{
if(channel[0x000] != 0x00 || channel[0x001] != 0xFF || channel[0x002] != 0xFF || channel[0x003] != 0xFF ||
channel[0x004] != 0xFF || channel[0x005] != 0xFF || channel[0x006] != 0xFF || channel[0x007] != 0xFF ||
channel[0x008] != 0xFF || channel[0x009] != 0xFF || channel[0x00A] != 0xFF ||
channel[0x00B] != 0x00) return null;
DicConsole.DebugWriteLine("CD checksums", "Data sector, address {0:X2}:{1:X2}:{2:X2}", channel[0x00C],
channel[0x00D], channel[0x00E]);
@@ -295,9 +295,6 @@ namespace DiscImageChef.Checksums
return null;
}
return null;
}
static bool? CheckCdSectorSubChannel(byte[] subchannel)
{
bool? status = true;
@@ -478,8 +475,8 @@ namespace DiscImageChef.Checksums
}
}
if((cdTextPack4[0] & 0x80) == 0x80)
{
if((cdTextPack4[0] & 0x80) != 0x80) return status;
ushort cdTextPack4Crc = BigEndianBitConverter.ToUInt16(cdTextPack4, 16);
byte[] cdTextPack4ForCrc = new byte[16];
Array.Copy(cdTextPack4, 0, cdTextPack4ForCrc, 0, 16);
@@ -487,13 +484,11 @@ namespace DiscImageChef.Checksums
DicConsole.DebugWriteLine("CD checksums", "Cyclic CDTP4 0x{0:X4}, Calc CDTP4 0x{1:X4}", cdTextPack4Crc,
calculatedCdtp4Crc);
if(cdTextPack4Crc != calculatedCdtp4Crc && cdTextPack4Crc != 0)
{
if(cdTextPack4Crc == calculatedCdtp4Crc || cdTextPack4Crc == 0) return status;
DicConsole.DebugWriteLine("CD checksums", "CD-Text Pack 4 CRC 0x{0:X4}, expected 0x{1:X4}",
cdTextPack4Crc, calculatedCdtp4Crc);
status = false;
}
}
return status;
}

View File

@@ -305,8 +305,8 @@ namespace DiscImageChef.Checksums
/// <param name="bb">Outs parity symbols.</param>
public int encode_rs(int[] data, out int[] bb)
{
if(initialized)
{
if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
int i, j;
int feedback;
bb = new int[nn - kk];
@@ -339,9 +339,6 @@ namespace DiscImageChef.Checksums
return 0;
}
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
}
/*
* Performs ERRORS+ERASURES decoding of RS codes. If decoding is successful,
* writes the codeword into data[] itself. Otherwise data[] is unaltered.
@@ -364,8 +361,8 @@ namespace DiscImageChef.Checksums
/// <param name="noEras">Number of erasures.</param>
public int eras_dec_rs(ref int[] data, out int[] erasPos, int noEras)
{
if(initialized)
{
if(!initialized) throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
erasPos = new int[nn - kk];
int degLambda, el, degOmega;
int i, j, r;
@@ -438,8 +435,7 @@ namespace DiscImageChef.Checksums
q ^= alpha_to[reg[j]];
}
if(q == 0)
{
if(q != 0) continue;
/* store root and error location
* number indices
*/
@@ -447,7 +443,6 @@ namespace DiscImageChef.Checksums
loc[count] = nn - i;
count++;
}
}
if(count != noEras)
{
@@ -539,14 +534,12 @@ namespace DiscImageChef.Checksums
q ^= alpha_to[reg[j]];
}
if(q == 0)
{
if(q != 0) continue;
/* store root (index-form) and error location number */
root[count] = i;
loc[count] = nn - i;
count++;
}
}
#if DEBUG
DicConsole.DebugWriteLine("Reed Solomon", "\n Final error positions:\t");
@@ -599,8 +592,5 @@ namespace DiscImageChef.Checksums
return count;
}
throw new UnauthorizedAccessException("Trying to calculate RS without initializing!");
}
}
}

View File

@@ -246,12 +246,11 @@ namespace DiscImageChef.Checksums
* */
self.Bh[i].Digest[++self.Bh[i].Dlen] = 0;
self.Bh[i].H = HASH_INIT;
if(self.Bh[i].Dlen < SPAMSUM_LENGTH / 2)
{
if(self.Bh[i].Dlen >= SPAMSUM_LENGTH / 2) continue;
self.Bh[i].Halfh = HASH_INIT;
self.Bh[i].Halfdigest = 0;
}
}
else fuzzy_try_reduce_blockhash();
}
}