From 4c0c53742140ef6f35a5258e79f62a202fe9832e Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Mon, 9 Mar 2015 19:18:27 +0100 Subject: [PATCH] Avoid detaching pixmaps when it has not changed setDevicePixelRatio is often called unconditionally even when the devicePixelRatio matches the pixmap or image. This causes a lot of unncessary detaches wasting some memory. Change-Id: I27535b2b22312ec0edc9bdc00c99d322afb727c1 Reviewed-by: Gunnar Sletta --- src/gui/image/qimage.cpp | 4 ++++ src/gui/image/qpixmap.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index e33ab24243..dba42d4698 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1433,6 +1433,10 @@ void QImage::setDevicePixelRatio(qreal scaleFactor) { if (!d) return; + + if (scaleFactor == d->devicePixelRatio) + return; + detach(); d->devicePixelRatio = scaleFactor; } diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index 0a9b55ed24..db6ae54d26 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -682,6 +682,9 @@ void QPixmap::setDevicePixelRatio(qreal scaleFactor) if (isNull()) return; + if (scaleFactor == data->devicePixelRatio()) + return; + detach(); data->setDevicePixelRatio(scaleFactor); }