Minor optimization: since our list items cache their position information,
take advantage of this fact to make use of binary search in IndexOf(BListItem *), rather than using BList's linear search. Also use this mechanism to speed up HasItem(BListItem *). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28694 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -733,7 +733,13 @@ BListView::ItemAt(int32 index) const
|
||||
int32
|
||||
BListView::IndexOf(BListItem *item) const
|
||||
{
|
||||
return fList.IndexOf(item);
|
||||
if (item != NULL) {
|
||||
BPoint point(0.0, item->Top());
|
||||
int32 index = IndexOf(point);
|
||||
if (index >= 0 && fList.ItemAt(index) == item)
|
||||
return index;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// IndexOf
|
||||
@@ -779,7 +785,7 @@ BListView::LastItem() const
|
||||
bool
|
||||
BListView::HasItem(BListItem *item) const
|
||||
{
|
||||
return fList.HasItem(item);
|
||||
return IndexOf(item) != -1;
|
||||
}
|
||||
|
||||
// CountItems
|
||||
|
||||
Reference in New Issue
Block a user