mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fix integrity verification performance regression
Integrity verification would always be done on savedata, even when not needed
This commit is contained in:
parent
06fda75ab9
commit
1110c32cb1
1 changed files with 16 additions and 13 deletions
|
@ -31,7 +31,6 @@ namespace LibHac.IO
|
|||
BlockValidities = new Validity[SectorCount];
|
||||
}
|
||||
|
||||
// todo Take short path when integrity checks are disabled
|
||||
private void ReadImpl(Span<byte> destination, long offset, IntegrityCheckLevel integrityCheckLevel)
|
||||
{
|
||||
int count = destination.Length;
|
||||
|
@ -39,8 +38,6 @@ namespace LibHac.IO
|
|||
if (count < 0 || count > SectorSize)
|
||||
throw new ArgumentOutOfRangeException(nameof(destination), "Length is invalid.");
|
||||
|
||||
|
||||
|
||||
long blockIndex = offset / SectorSize;
|
||||
|
||||
if (BlockValidities[blockIndex] == Validity.Invalid && integrityCheckLevel == IntegrityCheckLevel.ErrorOnInvalid)
|
||||
|
@ -48,13 +45,10 @@ namespace LibHac.IO
|
|||
throw new InvalidDataException("Hash error!");
|
||||
}
|
||||
|
||||
if (Type != IntegrityStorageType.Save && integrityCheckLevel == IntegrityCheckLevel.None)
|
||||
{
|
||||
BaseStorage.Read(destination, offset);
|
||||
return;
|
||||
}
|
||||
bool needsHashCheck = integrityCheckLevel != IntegrityCheckLevel.None &&
|
||||
BlockValidities[blockIndex] == Validity.Unchecked;
|
||||
|
||||
if (BlockValidities[blockIndex] != Validity.Unchecked)
|
||||
if (Type != IntegrityStorageType.Save && !needsHashCheck)
|
||||
{
|
||||
BaseStorage.Read(destination, offset);
|
||||
return;
|
||||
|
@ -64,13 +58,22 @@ namespace LibHac.IO
|
|||
long hashPos = blockIndex * DigestSize;
|
||||
HashStorage.Read(hashBuffer, hashPos);
|
||||
|
||||
if (Type == IntegrityStorageType.Save && Util.IsEmpty(hashBuffer))
|
||||
if (Type == IntegrityStorageType.Save)
|
||||
{
|
||||
if (Util.IsEmpty(hashBuffer))
|
||||
{
|
||||
destination.Clear();
|
||||
BlockValidities[blockIndex] = Validity.Valid;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!needsHashCheck)
|
||||
{
|
||||
BaseStorage.Read(destination, offset);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
byte[] dataBuffer = ArrayPool<byte>.Shared.Rent(SectorSize);
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue