QIdentityProxyModel: remove slow bounds-checking, for more performance

If we're called out of bounds, sourceModel()->index() will take care of
returning an invalid model index anyway. So calling rowCount+columnCount
every time index() is called can be avoided. These calls can be particularly
slow when sitting on top of a stack of proxymodels. And index() itself is called
very often, i.e. when a proxymodel on top of us is used by a delegate
which calls data() for many different roles.

Change-Id: I45ad6249ea6c6c719a28d25a03b6e5003f4e49ee
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
This commit is contained in:
David Faure 2014-10-22 10:04:01 +02:00
parent 6700fb0bf0
commit 3de0f442b5

View File

@ -152,11 +152,8 @@ QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex& p
{
Q_ASSERT(parent.isValid() ? parent.model() == this : true);
Q_D(const QIdentityProxyModel);
if (!hasIndex(row, column, parent))
return QModelIndex();
const QModelIndex sourceParent = mapToSource(parent);
const QModelIndex sourceIndex = d->model->index(row, column, sourceParent);
Q_ASSERT(sourceIndex.isValid());
return mapFromSource(sourceIndex);
}