Commit 4edc715b authored by Christian Stenger's avatar Christian Stenger

AutoTest: Speed up finding parent items

We normally add new results to the last added
item, so processing the search for the parent
from bottom to top makes more sense and avoids
iterating over almost every item.

Change-Id: Iede08b9c0d4c80227d2e8fea9b002354f01d5b35
Reviewed-by: default avatarhjk <hjk@qt.io>
parent df61f129
......@@ -841,6 +841,18 @@ TreeItem *TreeItem::findAnyChild(const std::function<bool(TreeItem *)> &pred) co
return 0;
}
TreeItem *TreeItem::reverseFindAnyChild(const std::function<bool (TreeItem *)> &pred) const
{
auto end = m_children.rend();
for (auto it = m_children.rbegin(); it != end; ++it) {
if (pred(*it))
return *it;
if (TreeItem *found = (*it)->reverseFindAnyChild(pred))
return found;
}
return nullptr;
}
void TreeItem::clear()
{
while (childCount() != 0) {
......
......@@ -78,6 +78,8 @@ public:
void forSelectedChildren(const std::function<bool(TreeItem *)> &pred) const;
void forAllChildren(const std::function<void(TreeItem *)> &pred) const;
TreeItem *findAnyChild(const std::function<bool(TreeItem *)> &pred) const;
// like findAnyChild() but processes children from bottom to top
TreeItem *reverseFindAnyChild(const std::function<bool(TreeItem *)> &pred) const;
// Levels are 1-based: Child at Level 1 is an immediate child.
void forChildrenAtLevel(int level, const std::function<void(TreeItem *)> &pred) const;
......
......@@ -313,7 +313,7 @@ TestResultItem *TestResultModel::findParentItemFor(const TestResultItem *item,
TestResultItem *currentItem = static_cast<TestResultItem *>(it);
return currentItem->testResult()->isDirectParentOf(result, &needsIntermediate);
};
TestResultItem *parent = static_cast<TestResultItem *>(root->findAnyChild(predicate));
TestResultItem *parent = static_cast<TestResultItem *>(root->reverseFindAnyChild(predicate));
if (parent) {
if (needsIntermediate) {
// check if the intermediate is present already
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment