QtGui: replace some copies with swaps

This provides move speed even for non-C++11 compilers and avoids
having to call the copy assignment operator from within copy ctors.
(which will result in infinite recursion when using the copy-swap idiom).

Change-Id: I379bc8bf2c72d9f986c0f17f9eef56cd592e7a06
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
This commit is contained in:
Marc Mutz 2012-05-07 20:19:40 +02:00 committed by Qt by Nokia
parent 8f2c57ddb2
commit 7d63fa6edc
3 changed files with 4 additions and 5 deletions

View File

@ -187,8 +187,7 @@ QBitmap::QBitmap(const QString& fileName, const char *format)
QBitmap &QBitmap::operator=(const QPixmap &pixmap)
{
if (pixmap.isNull()) { // a null pixmap
QBitmap bm(0, 0);
QBitmap::operator=(bm);
QBitmap(0, 0).swap(*this);
} else if (pixmap.depth() == 1) { // 1-bit pixmap
QPixmap::operator=(pixmap); // shallow assignment
} else { // n-bit depth pixmap

View File

@ -983,7 +983,7 @@ QImage::QImage(const QImage &image)
{
if (image.paintingActive() || isLocked(image.d)) {
d = 0;
operator=(image.copy());
image.copy().swap(*this);
} else {
d = image.d;
if (d)

View File

@ -226,7 +226,7 @@ QPixmap::QPixmap(const QPixmap &pixmap)
return;
}
if (pixmap.paintingActive()) { // make a deep copy
operator=(pixmap.copy());
pixmap.copy().swap(*this);
} else {
data = pixmap.data;
}
@ -384,7 +384,7 @@ QPixmap &QPixmap::operator=(const QPixmap &pixmap)
return *this;
}
if (pixmap.paintingActive()) { // make a deep copy
*this = pixmap.copy();
pixmap.copy().swap(*this);
} else {
data = pixmap.data;
}