* Some small optimizations. Fix issue #40387

This commit is contained in:
Michaël Van Canneyt 2023-08-11 13:49:15 +02:00
parent 52da2011dd
commit f5280abe54
2 changed files with 8 additions and 18 deletions

View File

@ -344,22 +344,17 @@ end;
class procedure TSHA256.Stream(aStream: TStream; out aDigest: TSHA256Digest);
const
BUFFER_SIZE = 64*1024;
var
aLen : LongInt;
Buffer: TBytes;
Buffer: array[0 .. 64*1024 - 1] of Byte;
SHA256: TSHA256;
begin
Buffer:=Nil;
SHA256.Init;
SetLength(Buffer,BUFFER_SIZE);
repeat
aLen:=aStream.Read(Buffer, BUFFER_SIZE);
if aLen <> 0 then
SHA256.Update(PByte(Buffer),aLen);
aLen:=aStream.Read(Buffer, Length(Buffer));
if aLen>0 then
SHA256.Update(PByte(Buffer),aLen);
until aLen=0;
SHA256.Final;
aDigest:=SHA256.Digest;

View File

@ -517,22 +517,17 @@ end;
class procedure TSHA512.Stream(aStream: TStream; out aDigest: TSHA512Digest);
const
BUFFER_SIZE = 64*1024;
var
aLen : LongInt;
lBuffer: TBytes;
lBuffer: array[0 .. 64*1024 - 1] of Byte;
SHA512: TSHA512;
begin
lBuffer:=Nil;
SHA512.Init;
SetLength(lBuffer,BUFFER_SIZE);
repeat
aLen:=aStream.Read(lBuffer, BUFFER_SIZE);
if aLen <> 0 then
SHA512.Update(PByte(lBuffer),aLen);
aLen:=aStream.Read(lBuffer, Length(lBuffer));
if aLen>0 then
SHA512.Update(PByte(lBuffer),aLen);
until aLen=0;
SHA512.Final;
aDigest:=SHA512.Digest;