[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdevplatform] plugins/quickopen: Optimize: Greatly speed up painting of the QuickOpen list of files
From:       Milian Wolff <mail () milianw ! de>
Date:       2013-08-01 0:09:23
Message-ID: E1V4gSJ-0007KR-Ew () scm ! kde ! org
[Download RAW message or body]

Git commit b52d958d39dafcd43637f37a02049ab1c8f297e0 by Milian Wolff.
Committed on 01/08/2013 at 00:06.
Pushed by mwolff into branch 'master'.

Optimize: Greatly speed up painting of the QuickOpen list of files.

The bottleneck is the QPixmap creation from a KIcon. We now cache
the KIconLoader::Small icon. In my tests this is a difference of
day and night performance wise. Where scrolling in a longish list
easily took 100% CPU and felt sluggish before, it now is very smooth.

This allows us to remove the scrollbar hack, where we disabled it
when too many items where displayed. It's not neccessary anymore.

M  +29   -8    plugins/quickopen/projectfilequickopen.cpp
M  +0    -12   plugins/quickopen/quickopenplugin.cpp
M  +0    -2    plugins/quickopen/quickopenplugin.h

http://commits.kde.org/kdevplatform/b52d958d39dafcd43637f37a02049ab1c8f297e0

diff --git a/plugins/quickopen/projectfilequickopen.cpp \
b/plugins/quickopen/projectfilequickopen.cpp index 13d7f97..0a8bab0 100644
--- a/plugins/quickopen/projectfilequickopen.cpp
+++ b/plugins/quickopen/projectfilequickopen.cpp
@@ -132,17 +132,38 @@ QWidget* ProjectFileData::expandingWidget() const
     return 0;
 }
 
+static QString iconNameForUrl(const IndexedString& url)
+{
+    if (url.isEmpty()) {
+        return QString("tab-duplicate");
+    }
+    ProjectBaseItem* item = \
ICore::self()->projectController()->projectModel()->itemForUrl(url); +    if (item) {
+        return item->iconName();
+    }
+    return QString("unknown");
+}
+
 QIcon ProjectFileData::icon() const
 {
-    if (m_file.indexedUrl.isEmpty()) {
-        return KIcon("tab-duplicate");
-    } else {
-        ProjectBaseItem* item = \
                ICore::self()->projectController()->projectModel()->itemForUrl(m_file.indexedUrl);
                
-        if (item) {
-            return KIcon(item->iconName());
-        }
+    const QString& iconName = iconNameForUrl(m_file.indexedUrl);
+
+    /**
+     * FIXME: Move this cache into a more central place and reuse it elsewhere.
+     *        The project model e.g. could reuse this as well.
+     *
+     * Note: We cache here since otherwise displaying and esp. scrolling
+     *       in a large list of quickopen items becomes very slow.
+     */
+    static QHash<QString, QPixmap> iconCache;
+    QHash< QString, QPixmap >::iterator it = iconCache.find(iconName);
+    if (it != iconCache.constEnd()) {
+        return it.value();
     }
-    return KIcon("unknown");
+
+    const QPixmap& pixmap = KIconLoader::global()->loadIcon(iconName, \
KIconLoader::Small); +    iconCache.insert(iconName, pixmap);
+    return pixmap;
 }
 
 BaseFileDataProvider::BaseFileDataProvider()
diff --git a/plugins/quickopen/quickopenplugin.cpp \
b/plugins/quickopen/quickopenplugin.cpp index 3fe08af..1779219 100644
--- a/plugins/quickopen/quickopenplugin.cpp
+++ b/plugins/quickopen/quickopenplugin.cpp
@@ -420,8 +420,6 @@ void QuickOpenWidget::prepareShow()
   
   connect( o.list->selectionModel(), \
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), this, \
SLOT(currentChanged(QModelIndex,QModelIndex)) );  connect( o.list->selectionModel(), \
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, \
                SLOT(currentChanged(QItemSelection,QItemSelection)) );
-  
-  updateScrollBarState();
 }
 
 void QuickOpenWidgetDialog::run() {
@@ -506,14 +504,6 @@ void QuickOpenWidget::updateProviders() {
   m_model->enableProviders( checkedItems, checkedScopes );
 }
 
-void QuickOpenWidget::updateScrollBarState()
-{
-  if(m_model->rowCount(QModelIndex()) > rowCountForDisablingScrollBar)
-    o.list->verticalScrollBar()->setEnabled(false);
-  else
-    o.list->verticalScrollBar()->setEnabled(true);
-}
-
 void QuickOpenWidget::textChanged( const QString& str )
 {
   // "cheap" when something was just appended to the current filter
@@ -526,8 +516,6 @@ void QuickOpenWidget::applyFilter()
 {
   m_model->textChanged( m_filter );
 
-  updateScrollBarState();
-
   QModelIndex currentIndex = m_model->index(0, 0, QModelIndex());
   o.list->selectionModel()->setCurrentIndex( currentIndex, \
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows | \
QItemSelectionModel::Current );  
diff --git a/plugins/quickopen/quickopenplugin.h \
b/plugins/quickopen/quickopenplugin.h index 6de4bd0..75c330c 100644
--- a/plugins/quickopen/quickopenplugin.h
+++ b/plugins/quickopen/quickopenplugin.h
@@ -170,8 +170,6 @@ class QuickOpenWidget : public QMenu {
   void updateProviders();
   void doubleClicked ( const QModelIndex & index );
 
-  void updateScrollBarState();
-
   void applyFilter();
 
   private:


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic