From f1e81e617247b1c827755a31627325c33052407e Mon Sep 17 00:00:00 2001 From: Alex Wilson Date: Wed, 28 Dec 2011 22:29:58 -0700 Subject: [PATCH] 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. --- src/kits/interface/Layout.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/kits/interface/Layout.cpp b/src/kits/interface/Layout.cpp index 371588bf19..75d3932bdb 100644 --- a/src/kits/interface/Layout.cpp +++ b/src/kits/interface/Layout.cpp @@ -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;