AbstractItemView editorForIndex/indexForEditor speedup
authorABBAPOH <ABBAPOH@nextmail.ru>
Sat, 9 Jun 2012 12:22:50 +0000 (16:22 +0400)
committerQt by Nokia <qt-info@nokia.com>
Wed, 13 Jun 2012 21:22:28 +0000 (23:22 +0200)
Frequent calls to editorForIndex/indexForEditor are very slow because of an implicit
conversion from QModelIndex to QPersistentModelIndex.
This fix allows to avoid unnecessary conversions when there are no open
editors (most common case)

Change-Id: Ic072880c9f33a43a20b2a61a42c3ba215c5c33cb
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
src/widgets/itemviews/qabstractitemview.cpp

index bd70e83..fbe1bf9 100644 (file)
@@ -4196,6 +4196,10 @@ const QEditorInfo & QAbstractItemViewPrivate::editorForIndex(const QModelIndex &
 {
     static QEditorInfo nullInfo;
 
+    // do not try to search to avoid slow implicit cast from QModelIndex to QPersistentModelIndex
+    if (indexEditorHash.isEmpty())
+        return nullInfo;
+
     QIndexEditorHash::const_iterator it = indexEditorHash.find(index);
     if (it == indexEditorHash.end())
         return nullInfo;
@@ -4205,6 +4209,10 @@ const QEditorInfo & QAbstractItemViewPrivate::editorForIndex(const QModelIndex &
 
 QModelIndex QAbstractItemViewPrivate::indexForEditor(QWidget *editor) const
 {
+    // do not try to search to avoid slow implicit cast from QModelIndex to QPersistentModelIndex
+    if (indexEditorHash.isEmpty())
+        return QModelIndex();
+
    QEditorIndexHash::const_iterator it = editorIndexHash.find(editor);
     if (it == editorIndexHash.end())
         return QModelIndex();