forked from qt-creator/qt-creator
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: hjk <hjk@qt.io>
This commit is contained in:
@@ -841,6 +841,18 @@ TreeItem *TreeItem::findAnyChild(const std::function<bool(TreeItem *)> &pred) co
|
|||||||
return 0;
|
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()
|
void TreeItem::clear()
|
||||||
{
|
{
|
||||||
while (childCount() != 0) {
|
while (childCount() != 0) {
|
||||||
|
@@ -78,6 +78,8 @@ public:
|
|||||||
void forSelectedChildren(const std::function<bool(TreeItem *)> &pred) const;
|
void forSelectedChildren(const std::function<bool(TreeItem *)> &pred) const;
|
||||||
void forAllChildren(const std::function<void(TreeItem *)> &pred) const;
|
void forAllChildren(const std::function<void(TreeItem *)> &pred) const;
|
||||||
TreeItem *findAnyChild(const std::function<bool(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.
|
// Levels are 1-based: Child at Level 1 is an immediate child.
|
||||||
void forChildrenAtLevel(int level, const std::function<void(TreeItem *)> &pred) const;
|
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);
|
TestResultItem *currentItem = static_cast<TestResultItem *>(it);
|
||||||
return currentItem->testResult()->isDirectParentOf(result, &needsIntermediate);
|
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 (parent) {
|
||||||
if (needsIntermediate) {
|
if (needsIntermediate) {
|
||||||
// check if the intermediate is present already
|
// check if the intermediate is present already
|
||||||
|
Reference in New Issue
Block a user