[KPhotoAlbum] Performance issues

Robert L Krawitz rlk at alum.mit.edu
Fri Feb 10 02:46:19 GMT 2006


This change -- which adds a vector in addition to the list for holding
the thumbnails -- makes the thumbnail view much more responsive.
Flipping between pages now takes about 2 seconds if the thumbnails
aren't loaded; if they're already loaded, it's almost instantaneous.


[2(rlk)||{!26}<rlk-mobile>/home/rlk/sandbox/kphotoalbum-2006-01-28-noi18n/src/ThumbnailView]
$ diff -u ThumbnailView.h{~,}
--- ThumbnailView.h~    2006-01-28 23:38:50.000000000 -0500
+++ ThumbnailView.h     2006-02-09 21:37:58.000000000 -0500
@@ -3,6 +3,7 @@
 
 #include <qgridview.h>
 #include <qvaluelist.h>
+#include <qvaluevector.h>
 #include "imageclient.h"
 #include "set.h"
 #include "ThumbnailToolTip.h"
@@ -121,6 +122,12 @@
 
 private:
     QStringList _imageList;
+    QValueVector<QString> _imageVector;
+
+    /**
+     * Reload the value vector
+     */
+    void reloadVector(void);
 
     /**
      * When the user selects a date on the date bar the thumbnail view will
[2(rlk)||{!27}<rlk-mobile>/home/rlk/sandbox/kphotoalbum-2006-01-28-noi18n/src/ThumbnailView]
$ diff -u ThumbnailView.cpp{~,}
--- ThumbnailView.cpp~  2006-01-28 23:38:50.000000000 -0500
+++ ThumbnailView.cpp   2006-02-09 21:40:36.000000000 -0500
@@ -126,7 +126,14 @@
     painter->drawText( rect, align, title );
 }
 
-
+void ThumbnailView::ThumbnailView::reloadVector( void )
+{
+    _imageVector.clear();
+    _imageVector.reserve(_imageList.count());
+    for( QStringList::Iterator imageIt = _imageList.begin(); imageIt != _imageList.end(); ++imageIt )
+      _imageVector.append(*imageIt);
+}
+  
 
 void ThumbnailView::ThumbnailView::setImageList( const QStringList& list )
 {
@@ -135,6 +142,8 @@
     else
         _imageList = reverseList( list );
 
+    reloadVector();
+
     if ( isVisible() ) {
         updateGridSize();
         repaintScreen();
@@ -148,10 +157,10 @@
 QString ThumbnailView::ThumbnailView::fileNameInCell( int row, int col ) const
 {
     uint index = row * numCols() + col;
-    if ( index >= _imageList.count() )
+    if ( index >= _imageVector.count() )
         return QString::null;
     else
-        return _imageList[index];
+        return _imageVector[index];
 }
 
 /**
@@ -790,14 +799,14 @@
         _leftDrop = fileName;
         int index = _imageList.findIndex( fileName ) -1;
         if ( index != -1 )
-            _rightDrop = _imageList[index];
+            _rightDrop = _imageVector[index];
     }
 
     else {
         _rightDrop = fileName;
         uint index = _imageList.findIndex( fileName ) +1;
         if ( index != _imageList.count() )
-            _leftDrop = _imageList[index];
+            _leftDrop = _imageVector[index];
     }
 
     updateCell( _leftDrop );
@@ -893,6 +902,9 @@
 
     Options::instance()->setShowNewestFirst( direction == NewestFirst );
     _imageList = reverseList( _imageList );
+
+    reloadVector();
+
     if ( !_currentItem.isNull() )
         setCurrentItem( _currentItem );
     repaintScreen();




More information about the Kphotoalbum mailing list