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