Recent

Author Topic: [SOLVED] Improvement of procedure TSHA512Base.Update  (Read 1546 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[SOLVED] Improvement of procedure TSHA512Base.Update
« on: September 09, 2023, 09:16:27 am »
packages/fcl-hash/src/fpsha512.pp has
Code: Pascal  [Select][+][-]
  1. procedure TSHA512Base.Update(PBuf: PByte; Size: UInt32);
  2. var
  3.   Len: UInt32;
  4. begin
  5.   Inc(TotalLength, Int64(UInt32(Size)) * 8);
  6.   while Size > 0 do
  7.   begin
  8.     Len:=Sizeof(Buffer)-Index;
  9.     if Len <= UInt32(Size) then
  10.     begin
  11.       Move(PBuf^, Buffer[Index], Len);
  12.       Dec(Size, Len);
  13.       Inc(PBuf, Len);
  14.       Compress;
  15.       Self.Index := 0;
  16.     end else
  17.     begin
  18.       Move(PBuf^, Buffer[Index], Size);
  19.       Inc(Self.Index, Size);
  20.       Size := 0;
  21.     end;
  22.   end;
  23. 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.
« Last Edit: September 20, 2023, 11:28:53 am by lagprogramming »

AlexTP

  • Hero Member
  • *****
  • Posts: 2519
    • UVviewsoft

abouchez

  • Full Member
  • ***
  • Posts: 120
    • Synopse
Re: Improvement of procedure TSHA512Base.Update
« Reply #2 on: September 09, 2023, 10:46:20 am »
Sounds like a non-improvement to me.

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

AlexTP

  • Hero Member
  • *****
  • Posts: 2519
    • UVviewsoft
Re: Improvement of procedure TSHA512Base.Update
« Reply #3 on: September 09, 2023, 12:13:27 pm »
Anyway, I keep posting suggestions from 'lagprogramming'. He does minor work, but useful.

 

TinyPortal © 2005-2018