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
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to