Fix bug in BLayout::RemoveView().

Fix typo-induced bug causing (in many cases) the wrong item to be removed from the layout!
Also, improve performance from O(n * m) to O(n), although n and m will always be quite small in practice, we might as well.
This commit is contained in:
Alex Wilson 2011-12-28 22:29:58 -07:00
parent 2cb6157746
commit f1e81e6172

View File

@ -200,16 +200,18 @@ BLayout::RemoveView(BView* child)
bool removed = false;
// a view can have any number of layout items - we need to remove them all
BView::Private viewPrivate(child);
for (int32 i = viewPrivate.CountLayoutItems() - 1; i >= 0; i--) {
BLayoutItem* item = viewPrivate.LayoutItemAt(i);
int32 remaining = BView::Private(child).CountLayoutItems();
for (int32 i = CountItems() - 1; i >= 0 && remaining > 0; i--) {
BLayoutItem* item = ItemAt(i);
if (item->Layout() != this)
if (item->View() != child)
continue;
RemoveItem(i);
removed = true;
delete item;
remaining--;
removed = true;
}
return removed;