Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-08

TStream.ReadByte/Word/DWord implementation

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bram Kuijvenhoven

Hi!

I saw that the implementations of TStream.ReadByte/Word/DWord (in rtl/objpas/classes/streams.inc) each use a local variable:

  function TStream.ReadByte : Byte;
    var
       b : Byte;
    begin
       ReadBuffer(b,1);
       ReadByte:=b;
    end;
  function TStream.ReadWord : Word;
    var
       w : Word;
    begin
       ReadBuffer(w,2);
       ReadWord:=w;
    end;
  function TStream.ReadDWord : Cardinal;
    var
       d : Cardinal;
    begin
       ReadBuffer(d,4);
       ReadDWord:=d;
    end;

Isn't it (way) more optimal to use the Result variable here? E.g.

  function TStream.ReadByte : Byte;
    begin
       ReadBuffer(Result,1);
    end;
  function TStream.ReadWord : Word;
    begin
       ReadBuffer(Result,2);
    end;
  function TStream.ReadDWord : Cardinal;
    begin
       ReadBuffer(Result,4);
    end;

As these are typical inner loop functions (at least, when not doing buffered access), I'd suggest patching this if it increases performance.

Regards,

Bram

Reply by email