Optimized reading for empty run of blocks in partclone.

This commit is contained in:
2017-09-21 18:30:26 +01:00
parent d2fff1155e
commit 974af4efed

View File

@@ -219,14 +219,7 @@ namespace DiscImageChef.DiscImages
return true; return true;
} }
bool IsEmpty(ulong sectorAddress) // TODO: Find a way to optimize this, it's insanely slow!
{
if(sectorAddress > (ulong)byteMap.LongLength - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), string.Format("Sector address {0} not found", sectorAddress));
return byteMap[sectorAddress] == 0;
}
ulong BlockOffset(ulong sectorAddress) ulong BlockOffset(ulong sectorAddress)
{ {
ulong blockOff = 0; ulong blockOff = 0;
@@ -243,7 +236,7 @@ namespace DiscImageChef.DiscImages
if(sectorAddress > ImageInfo.sectors - 1) if(sectorAddress > ImageInfo.sectors - 1)
throw new ArgumentOutOfRangeException(nameof(sectorAddress), string.Format("Sector address {0} not found", sectorAddress)); throw new ArgumentOutOfRangeException(nameof(sectorAddress), string.Format("Sector address {0} not found", sectorAddress));
if(IsEmpty(sectorAddress)) if(byteMap[sectorAddress] == 0)
return new byte[pHdr.blockSize]; return new byte[pHdr.blockSize];
byte[] sector; byte[] sector;
@@ -275,6 +268,19 @@ namespace DiscImageChef.DiscImages
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
bool allEmpty = true;
for(uint i = 0; i < length; i++)
{
if(byteMap[sectorAddress + i] != 0)
{
allEmpty = false;
break;
}
}
if(allEmpty)
return new byte[pHdr.blockSize * length];
for(uint i = 0; i < length; i++) for(uint i = 0; i < length; i++)
{ {
byte[] sector = ReadSector(sectorAddress + i); byte[] sector = ReadSector(sectorAddress + i);