diff --git a/src/libs/utils/treemodel.cpp b/src/libs/utils/treemodel.cpp index 5281ab33f5b..db8923e372a 100644 --- a/src/libs/utils/treemodel.cpp +++ b/src/libs/utils/treemodel.cpp @@ -919,11 +919,9 @@ QModelIndex BaseTreeModel::parent(const QModelIndex &idx) const if (!grandparent) return QModelIndex(); - for (int i = 0, n = grandparent->childCount(); i < n; ++i) - if (grandparent->childAt(i) == parent) - return createIndex(i, 0, static_cast(parent)); - - return QModelIndex(); + // This is on the performance-critical path for ItemViewFind. + const int i = grandparent->m_children.indexOf(parent); + return createIndex(i, 0, static_cast(parent)); } int BaseTreeModel::rowCount(const QModelIndex &idx) const diff --git a/src/libs/utils/treemodel.h b/src/libs/utils/treemodel.h index 8782d7b37df..60db234d3b4 100644 --- a/src/libs/utils/treemodel.h +++ b/src/libs/utils/treemodel.h @@ -66,7 +66,7 @@ public: using const_iterator = QVector::const_iterator; using value_type = TreeItem *; - int childCount() const { return end() - begin(); } + int childCount() const { return m_children.size(); } int indexInParent() const; TreeItem *childAt(int index) const; int indexOf(const TreeItem *item) const; diff --git a/src/plugins/coreplugin/find/itemviewfind.cpp b/src/plugins/coreplugin/find/itemviewfind.cpp index 3588f125ece..cc2dd466e54 100644 --- a/src/plugins/coreplugin/find/itemviewfind.cpp +++ b/src/plugins/coreplugin/find/itemviewfind.cpp @@ -249,12 +249,13 @@ QModelIndex ItemViewFind::nextIndex(const QModelIndex &idx, bool *wrapped) const return model->index(0, 0); // same parent has more columns, go to next column - if (idx.column() + 1 < model->columnCount(idx.parent())) - return model->index(idx.row(), idx.column() + 1, idx.parent()); + const QModelIndex parentIdx = idx.parent(); + if (idx.column() + 1 < model->columnCount(parentIdx)) + return model->index(idx.row(), idx.column() + 1, parentIdx); // tree views have their children attached to first column // make sure we are at first column - QModelIndex current = model->index(idx.row(), 0, idx.parent()); + QModelIndex current = model->index(idx.row(), 0, parentIdx); // check for children if (d->m_option == FetchMoreWhileSearching && model->canFetchMore(current))