From 4bd3c01eaab0ecbeb0c2f8cb37a6c4b8ed617d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 28 Nov 2005 15:48:43 +0000 Subject: [PATCH] _AddChildToList() was very inefficient in case there was a "before" view specified. Also, it now drops into the debugger in case "before" doesn't belong to us already. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15198 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/View.cpp | 65 +++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 02c1b787d1..32e9344a1f 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -3872,47 +3872,48 @@ BView::_RemoveChildFromList(BView* child) bool -BView::_AddChildToList(BView* view, BView* before) +BView::_AddChildToList(BView* child, BView* before) { - if (!view) + if (!child) + return false; + if (child->fParent != NULL) { + debugger("View already belongs to someone else"); + return false; + } + if (before != NULL && before->fParent != this) { + debugger("Invalid before view"); return false; - - BView *current = fFirstChild; - BView *last = current; - - while (current && current != before) { - last = current; - current = current->fNextSibling; } - if (!current && before) - return false; + if (before != NULL) { + // add view before this one + child->fNextSibling = before; + child->fPreviousSibling = before->fPreviousSibling; + if (child->fPreviousSibling != NULL) + child->fPreviousSibling->fNextSibling = child; - // we're at begining of the list, OR between two elements - if (current) { - if (current == fFirstChild) { - view->fNextSibling = current; - current->fPreviousSibling = view; - fFirstChild = view; - } else { - view->fNextSibling = current; - view->fPreviousSibling = current->fPreviousSibling; - current->fPreviousSibling->fNextSibling = view; - current->fPreviousSibling = view; - } + before->fPreviousSibling = child; + if (fFirstChild == before) + fFirstChild = child; } else { - // we have reached the end of the list + // add view to the end of the list + BView *last = fFirstChild; + while (last != NULL && last->fNextSibling != NULL) { + last = last->fNextSibling; + } - // if last!=NULL then we add to the end. Otherwise, view is the - // first chiild in the list - if (last) { - last->fNextSibling = view; - view->fPreviousSibling = last; - } else - fFirstChild = view; + if (last != NULL) { + last->fNextSibling = child; + child->fPreviousSibling = last; + } else { + fFirstChild = child; + child->fPreviousSibling = NULL; + } + + child->fNextSibling = NULL; } - view->fParent = this; + child->fParent = this; return true; }