[fpc-devel] TStream.ReadByte/Word/DWord implementation

Bram Kuijvenhoven kuifwaremailinglists at xs4all.nl
Wed Aug 2 12:08:23 CEST 2006


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



More information about the fpc-devel mailing list