[fpc-devel] about commit r29324
Michael Van Canneyt
michael at freepascal.org
Sun Dec 28 15:36:49 CET 2014
On Sun, 28 Dec 2014, Mattias Gaertner wrote:
> Hi,
>
> forwarded from Zeljko:
>
> It's about fpc issue
> http://bugs.freepascal.org/view.php?id=26370
>
> It seems that TVariantArrayIterator.AtEnd loops for all Dims for no reason, so have
> impact on performance.
>
> *current implementation*
> function TVariantArrayIterator.AtEnd: Boolean;
> var
> i : sizeint;
> begin
> result:=false;
> for i:=0 to Pred(Dims) do
> if Coords^[i] >= Bounds^[i].LowBound + Bounds^[i].ElementCount then
> result:=true;
> end;
>
> *optimized implementation*
> function TVariantArrayIterator.AtEnd: Boolean;
> var
> i : sizeint;
> begin
> result:=false;
> for i:=0 to Pred(Dims) do
> if Coords^[i] >= Bounds^[i].LowBound + Bounds^[i].ElementCount then
> begin
> result:=true;
> break;
> end;
> end;
Or, better yet
var
i : sizeint;
begin
Result:=false;
I:=0;
While (Not Result) and (I<=Pred(Dims)) do
begin
Result:= Coords^[i] >= Bounds^[i].LowBound + Bounds^[i].ElementCount;
Inc(I);
end;
end;
People really don't seem to get booleans, and why they scorn "While" is beyond me. All these ugly "break" statements :(
You may optimize even more by calculating Max:=pred(dims) once and doing I<=Max;
Michael.
More information about the fpc-devel
mailing list