[haiku-development] Re: Hello, and a BBitmap question.

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 07 Jun 2008 12:34:18 +0200

On 2008-06-07 at 12:30:40 [+0200], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> 
wrote:
> "Rene Gollent" <anevilyak@xxxxxxxxx> wrote:
> > while (fParent->CountChildren() > 0) {
> > fParent->RemoveChild(fParent->ChildAt(0));
> > printf("%d\n", fParent->CountChildren());
> > }
> 
> And since BView::CountChildren() is O(n), you should actually do:
> 
> while (true) {
>     BView* view = fParent->ChildAt(0);
>     if (view == NULL)
>         break;
> 
>     fParent->RemoveChild(view);
> }

Which can be written more compactly:

while (BView* view = fParent->ChildAt(0))
        fParent->RemoveChild(view);

CU, Ingo

Other related posts: