Andreas Ekstrand wrote:
> Hi again,
> 
> I am trying to update to the latest 1.3 revision to get solutions to other 
> problems but I keep bumping into other things not fixed yet, of which this 
> slow Fl_Group::clear is one of the more serious. It really keeps us from 
> using the latest revision and we can't let our product stay with an old 
> revision any longer.
> 
> I know that my usage of Fl_Group isn't that common, but since it worked much 
> better before the STR #1894 fix, I think there should be some way for me to 
> clear the contents of a group much faster. Any suggestions?

        I haven't been following this thread or STR#1894,
        but looking at the code, it looks like clear() calls delete() and 
remove()
        in a loop to destroy + remove each child.

        Apparently it used to just zero the array right off, then delete the 
children,
        which was fast, but messed up the children's destructors if they tried 
to look
        back at the parent() group.

        I'm guessing remove() is the problem, because looking at the code for 
remove(),
        each remove operation shuffles the array down into the position that 
was remove()ed.

        Offhand I'd say say clear() seems to be doing the slowest thing possible
        wrt to how remove() currently operates.

        remove() shuffles the array downward to fill in the new gap,
        so if you always remove the first element, the entire array above it 
has to
        shuffle downward.

        It seems to me if clear() started at the end of the array and worked 
its way
        downward, each remove() operation wouldn't have to do any shuffling.

        If I understand things correctly, this might be a one liner fix
        to Fl_Group::clear(), specifically in this section:

while (children_) {
  //Fl_Widget *o = child(o);            // <-- COMMENT THIS OUT
  Fl_Widget *o = child(children_-1);    // <-- USE THIS INSTEAD
  if ( o->parent() == this ) {
    remove(o);
    delete(o);
  } else {
    remove(o);
  }
}

        I didn't try this, but I *think* that will help remove()
        do less work on each iter.

        Comments welcome.
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to