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:
parent
8f2c57ddb2
commit
7d63fa6edc
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user