mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Optimized reading for empty run of blocks in partclone.
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user