[SOLVED] Improvement of procedure TSHA512Base.Update lazarus / 64-FPC development ---------------------------------------------------------------------- lagprogramming · 2023-09-09 07:16 packages/fcl-hash/src/fpsha512.pp has Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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. ---------------------------------------------------------------------- AlexTP · 2023-09-09 07:38 Posted to https://gitlab.com/freepascal.org/fpc/source/-/issues/40435 ---------------------------------------------------------------------- abouchez · 2023-09-09 08:46 Sounds like a non-improvement to me. Performance would be identical for sure, and readability not enhanced to my taste. ---------------------------------------------------------------------- AlexTP · 2023-09-09 10:13 Anyway, I keep posting suggestions from 'lagprogramming'. He does minor work, but useful.