REFACTOR: Invert 'if' statement to reduce nesting.

This commit is contained in:
2017-12-21 06:06:19 +00:00
parent 0077694c75
commit 4ce965e6cf
9 changed files with 116 additions and 133 deletions

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -170,12 +169,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -82,8 +82,8 @@ namespace Extents
} }
// Expands existing extent end // Expands existing extent end
if(item == backend[i].Item2 + 1) if(item != backend[i].Item2 + 1) continue;
{
removeOne = backend[i]; removeOne = backend[i];
if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1) if(i < backend.Count - 1 && item == backend[i + 1].Item1 - 1)
@@ -95,7 +95,6 @@ namespace Extents
break; break;
} }
}
if(itemToAdd != null) if(itemToAdd != null)
{ {
@@ -171,12 +170,11 @@ namespace Extents
} }
// Extent is only element // Extent is only element
if(item == extent.Item1 && item == extent.Item2) if(item != extent.Item1 || item != extent.Item2) continue;
{
toRemove = extent; toRemove = extent;
break; break;
} }
}
// Item not found // Item not found
if(toRemove == null) return false; if(toRemove == null) return false;

View File

@@ -145,12 +145,11 @@ namespace DiscImageChef
{ {
if(i == start) return ""; if(i == start) return "";
if(SpacePaddedString[i - 1] != 0x20) if(SpacePaddedString[i - 1] == 0x20) continue;
{
len = i; len = i;
break; break;
} }
}
return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len); return len == 0 ? "" : encoding.GetString(SpacePaddedString, start, len);
} }