From 5b9e566b4d009ddb79f4c7d7e17ef0b8b4024859 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 2 Sep 2014 10:32:43 +0200 Subject: QImage: add a qMove() The color table is passed by value (good for C++11), so when the argument is assigned to the member variable, that's a good spot for a move assignment. However, the argument is also declared const. The standard says that top-level const is ignored, but some compilers (I know about SunCC) think differently, so we cannot remove it. Instead, we do a const_cast. It is well-defined: Even though apparently the argument was declared as const, the standard says the const is not there, and no sane compiler would put the argument copy into read-only memory. Add a reminder to remove the top-level const from the signature come Qt 6. Change-Id: Iac18846ba669de0a30da620685ad1438c267e193 Reviewed-by: Olivier Goffart --- src/gui/image/qimage.cpp | 2 +- src/gui/image/qimage.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index c3b4b1444a..5de686c1ea 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1368,7 +1368,7 @@ void QImage::setColorTable(const QVector colors) if (!d) return; - d->colortable = colors; + d->colortable = qMove(const_cast&>(colors)); d->has_alpha_clut = false; for (int i = 0; i < d->colortable.size(); ++i) { if (qAlpha(d->colortable.at(i)) != 255) { diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 844bbb2eba..3e73462efc 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -232,7 +232,7 @@ public: void setPixel(const QPoint &pt, uint index_or_rgb); QVector colorTable() const; - void setColorTable(const QVector colors); + void setColorTable(const QVector colors); // ### Qt 6: remove const qreal devicePixelRatio() const; void setDevicePixelRatio(qreal scaleFactor); -- cgit v1.2.3