Sign in or sign up before continuing. Don't have an account yet? Register now to get started.
Register now
Improvement of procedure TSHA512Base.Update
from 'lagprogramming'. packages/fcl-hash/src/fpsha512.pp has ```pascal procedure TSHA512Base.Update(PBuf: PByte; Size: UInt32); var Len: UInt32; begin Inc(TotalLength, Int64(UInt32(Size)) * 8); while Size > 0 do begin Len:=Sizeof(Buffer)-Index; if Len <= UInt32(Size) then begin Move(PBuf^, Buffer[Index], Len); Dec(Size, Len); Inc(PBuf, Len); Compress; Self.Index := 0; end else begin Move(PBuf^, Buffer[Index], Size); Inc(Self.Index, Size); Size := 0; end; end; end; ``` In order to exit the loop the original code sets a zero value to Size. The attached patch changes the line "Size := 0;" with "Break;". In addition to increased readability, the CPU will avoid a failed prediction of the "Size > 0" condition. [sh.diff](/uploads/f44a60da19681de2c5e7930e54a1ffaf/sh.diff)
issue