On Mon, 22 Jan 2007 22:04:40 +0300
Al Boldi <[EMAIL PROTECTED]> wrote:
> Mattias Gaertner wrote:
> > Al Boldi <[EMAIL PROTECTED]> wrote:
> > > Mattias Gaertner wrote:
> > > > Al Boldi <[EMAIL PROTECTED]> wrote:
> > > > > > > Preallocating the tree in TTreeView could improve its
> > > > > > > speed a lot.
> > > > > >
> > > > > > I doubt that. It already works with exponential growth.
> > > > >
> > > > > Preallocate in 16sec ============
> > > > > TreeView1.BeginUpdate;
> > > > > TreeView1.Items.Clear;
> > > > > for i:=1 to 100000 do
> > > > > TreeView1.Items.Add(nil,'');
> > > > > TreeView1.EndUpdate;
> > > >
> > > > I improved it. Please try.
> > >
> > > Do you have a patch against 0.9.15?
> >
> > I can create one, but I'm not sure, if the rest of 0.9.15 will work
> > with it.
> > Attached.
>
> Thanks!
>
> It didn't apply, but with this change
>
> /////////////
> else if Index>Count-5 then begin
> // optimization for the last nodes
> Result:=GetLastSubNode;
> i:=Count-1;
> while (Index<i) do
> Result:=Result.GetPrev;
> end
> /////////////
This above was wrong. I fixed it. A dec(i) was missing.
> on this
>
> > No preallocation > 2min ^C ======
> > TreeView1.BeginUpdate;
> > TreeView1.Items.Clear;
> > for i:=1 to 100000 do begin
> > TreeView1.Items.Add(nil,'tst'+inttostr(i));
> > for j:=1 to 10 do
> > TreeView1.Items[i-1].Text:=IntToStr(i)+','+IntToStr(j);
> > end;
> > TreeView1.EndUpdate;
> > =================================
>
> speeds thru in 19sec.
>
> TStringGrid is still 4 times faster.
With the current version it runs here in 1 second.
BTW, TStringGrid was 4 times faster, because you optimized the way
items are added. Doing the same for TTreeView, would mean, instead of
TreeView1.Items[i-1] use TreeView1.Items.GetLastNode.
My point is, that the IDE processes line by line and adds single lines
to the viewer control. This is bad for grids (at the moment).
> What change is required for preallocation?
Some changes to comctrls.pp and various places in treeview.inc. The
TTreeNodes.IndexOfTopLvlItem now works in O(1), instead of O(n).
Mattias
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives