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 <gunnar@sletta.org>
bb10
David Edmundson 2015-03-09 19:18:27 +01:00
parent 1cc8ec1e78
commit 4c0c537421
2 changed files with 7 additions and 0 deletions

View File

@ -1433,6 +1433,10 @@ void QImage::setDevicePixelRatio(qreal scaleFactor)
{
if (!d)
return;
if (scaleFactor == d->devicePixelRatio)
return;
detach();
d->devicePixelRatio = scaleFactor;
}

View File

@ -682,6 +682,9 @@ void QPixmap::setDevicePixelRatio(qreal scaleFactor)
if (isNull())
return;
if (scaleFactor == data->devicePixelRatio())
return;
detach();
data->setDevicePixelRatio(scaleFactor);
}