From 6548773ad6d703aac0d0994a55c78a9ab5a73507 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 1 Jul 2014 09:02:10 -0700 Subject: Implement a cache for the scaled images No point in scaling them every time the user looks at the dive. Over time this may waste some memory (especially if people have a ton of pictures and let the process run a very long time). For now I won't worry about that. Fixes #577 Signed-off-by: Dirk Hohndel --- qt-ui/divepicturewidget.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp index 6742fc274..cadbe04e6 100644 --- a/qt-ui/divepicturewidget.cpp +++ b/qt-ui/divepicturewidget.cpp @@ -2,6 +2,7 @@ #include #include #include +#include DivePictureModel *DivePictureModel::instance() { @@ -18,10 +19,16 @@ typedef QList SPixmapList; SPixmap scaleImages(const QString &s) { - QImage p = QImage(s).scaled(128, 128, Qt::KeepAspectRatio); + static QHash cache; SPixmap ret; ret.first = s; - ret.second = p; + if (cache.contains(s)) { + ret.second = cache.value(s); + } else { + QImage p = QImage(s).scaled(128, 128, Qt::KeepAspectRatio); + cache.insert(s, p); + ret.second = p; + } return ret; } -- cgit v1.2.3-70-g09d2