[Lazarus] Extending TRect breaks Lazarus

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Nov 9 11:19:42 CET 2015


On Mon, 9 Nov 2015 09:38:27 +0000
Lukasz Sokol <el.es.cr at gmail.com> wrote:

>[...] On 07/11/15 11:01, Mattias Gaertner wrote:
> > On Sat, 7 Nov 2015 11:39:44 +0100
> > Jürgen Hestermann <juergen.hestermann at gmx.de> wrote:
> > 
> [...]
> >> -----------------------------
> >> with PathArray[High(PathArray)]^ do
> >>     fillchar(StatisticOfFiles,sizeof(StatisticOfFiles),0);
> >> -----------------------------
> >>
> >> instead of this:
> >>
> >> -----------------------------
> >> fillchar(PathArray[High(PathArray)]^.StatisticOfFiles,sizeof(PathArray[High(PathArray)]^.StatisticOfFiles),0);
> >> -----------------------------
> [...]
> > 
> > LastPath:=PathArray[High(PathArray)];
> > fillchar(LastPath^.StatisticOfFiles,sizeof(LastPath^.StatisticOfFiles),0);
> > 
> 
> Will this form produce same code (as in memory footprint and machine code/so-called performance) ?

The above three are not the same.

The second version executes the With-Expression multiple times, so
unless the compiler optimizes a lot it will create more code and will be
slower.

The first and third versions have the same amount of reads/writes and
with optimizations (-O2 or higher) create the same assembler code.
Without optimizations the first is a bit faster, because the compiler
stores the With-Pointer in a register, while in third version it stores
it on the stack.

 
> (but then, the last form, will have the variable declared explicitly, which probably means more complicated code around this region etc.?)

A local variable is bread and butter for the compiler. There is
nothing complicated about it.
I would argue that giving an expression a describing name can make code
less complicated.

Mattias




More information about the Lazarus mailing list