[fpc-pascal] A check before setting a property (or the cost of a call instruction)
Jonas Maebe
jonas.maebe at elis.ugent.be
Thu Jul 22 23:33:06 CEST 2010
On 22 Jul 2010, at 23:10, Luiz Americo Pereira Camara wrote:
> In Lazarus i just committed the following code:
>
> if Alignment <> FDataLink.Field.Alignment then
> Alignment := FDataLink.Field.Alignment;
>
> but i could do also:
>
> Alignment := FDataLink.Field.Alignment;
>
> The setter property of Alignment already checks if the passed value
> is equal:
[snip]
> Is worth removing the check?
Yes.
> The cost of not doing the call compensates the extra code added by
> the check?
In general, it's best to keep any code that is not speed critical as
small as possible. The reason is that it will then displace less other
code from the instruction cache, and removing less code from the
instruction cache will almost always result in faster programs than
some micro-optimization here or there.
Jonas
More information about the fpc-pascal
mailing list