Forum > FPC development

[SOLVED] Improvement of procedure TSHA512Base.Update


packages/fcl-hash/src/fpsha512.pp has

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.

Posted to

Sounds like a non-improvement to me.

Performance would be identical for sure, and readability not enhanced to my taste.

Anyway, I keep posting suggestions from 'lagprogramming'. He does minor work, but useful.


[0] Message Index

Go to full version