From f36a013be529b32a0f1b8e2fffb3153609f15ccd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 15 Mar 2022 21:20:46 +0100 Subject: QtGui: compile-optimize inline swap functions Instead of using the overly-generic qSwap() monster, use - qt_ptr_swap() for swapping raw pointers - member-swap for swapping smart pointers - std::swap() for swapping scalars In QtCore, this has proven to give a nice reduction in compile time for Qt users, cf. b1b0c2970e480ef460a61f37fa430dc443390358. Task-number: QTBUG-97601 Change-Id: I987ff95e8751a22a4f283655d8225dd16de21178 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer (cherry picked from commit c839efb07a6aa3b487dac5f86f905f35ef2c3a08) Reviewed-by: Qt Cherry-pick Bot --- src/gui/image/qicon.h | 2 +- src/gui/image/qimage.h | 2 +- src/gui/image/qpixmap.h | 2 +- src/gui/image/qpixmapcache.h | 2 +- src/gui/kernel/qcursor.h | 2 +- src/gui/kernel/qeventpoint.h | 2 +- src/gui/kernel/qkeysequence.h | 2 +- src/gui/kernel/qpalette.h | 4 ++-- src/gui/painting/qbrush.h | 2 +- src/gui/painting/qcolorspace.h | 2 +- src/gui/painting/qpagelayout.h | 2 +- src/gui/painting/qpageranges.h | 2 +- src/gui/painting/qpagesize.h | 2 +- src/gui/painting/qpen.h | 2 +- src/gui/painting/qregion.h | 2 +- src/gui/text/qfont.h | 4 ++-- src/gui/text/qfontinfo.h | 2 +- src/gui/text/qfontmetrics.h | 4 ++-- src/gui/text/qglyphrun.h | 2 +- src/gui/text/qrawfont.h | 2 +- src/gui/text/qstatictext.h | 2 +- src/gui/text/qtextcursor.h | 2 +- src/gui/text/qtextformat.h | 2 +- 23 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/gui/image/qicon.h b/src/gui/image/qicon.h index fab8c3fe21..d5e192893a 100644 --- a/src/gui/image/qicon.h +++ b/src/gui/image/qicon.h @@ -70,7 +70,7 @@ public: QIcon &operator=(const QIcon &other); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QIcon) inline void swap(QIcon &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } bool operator==(const QIcon &) const = delete; bool operator!=(const QIcon &) const = delete; diff --git a/src/gui/image/qimage.h b/src/gui/image/qimage.h index 6561359dae..511e1dd864 100644 --- a/src/gui/image/qimage.h +++ b/src/gui/image/qimage.h @@ -139,7 +139,7 @@ public: QImage &operator=(const QImage &); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QImage) void swap(QImage &other) noexcept - { qSwap(d, other.d); } + { qt_ptr_swap(d, other.d); } bool isNull() const; diff --git a/src/gui/image/qpixmap.h b/src/gui/image/qpixmap.h index 9d4d8e582d..e132277421 100644 --- a/src/gui/image/qpixmap.h +++ b/src/gui/image/qpixmap.h @@ -77,7 +77,7 @@ public: QPixmap &operator=(const QPixmap &); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QPixmap) inline void swap(QPixmap &other) noexcept - { qSwap(data, other.data); } + { data.swap(other.data); } bool operator==(const QPixmap &) const = delete; bool operator!=(const QPixmap &) const = delete; diff --git a/src/gui/image/qpixmapcache.h b/src/gui/image/qpixmapcache.h index 33021d1773..3a273fc3c8 100644 --- a/src/gui/image/qpixmapcache.h +++ b/src/gui/image/qpixmapcache.h @@ -63,7 +63,7 @@ public: { return !operator==(key); } Key &operator =(const Key &other); - void swap(Key &other) noexcept { qSwap(d, other.d); } + void swap(Key &other) noexcept { qt_ptr_swap(d, other.d); } bool isValid() const noexcept; private: diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index c1d45cc41b..0bc54a3d82 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -90,7 +90,7 @@ public: QCursor(QCursor &&other) noexcept : d(qExchange(other.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCursor) - void swap(QCursor &other) noexcept { qSwap(d, other.d); } + void swap(QCursor &other) noexcept { qt_ptr_swap(d, other.d); } operator QVariant() const; diff --git a/src/gui/kernel/qeventpoint.h b/src/gui/kernel/qeventpoint.h index fbcdc20193..1e4eca040d 100644 --- a/src/gui/kernel/qeventpoint.h +++ b/src/gui/kernel/qeventpoint.h @@ -102,7 +102,7 @@ public: bool operator!=(const QEventPoint &other) const noexcept { return !operator==(other); } ~QEventPoint(); inline void swap(QEventPoint &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } QPointF position() const; QPointF pressPosition() const; diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h index 61001dddbc..f614046748 100644 --- a/src/gui/kernel/qkeysequence.h +++ b/src/gui/kernel/qkeysequence.h @@ -186,7 +186,7 @@ public: QKeyCombination operator[](uint i) const; QKeySequence &operator=(const QKeySequence &other); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QKeySequence) - void swap(QKeySequence &other) noexcept { qSwap(d, other.d); } + void swap(QKeySequence &other) noexcept { qt_ptr_swap(d, other.d); } bool operator==(const QKeySequence &other) const; inline bool operator!= (const QKeySequence &other) const diff --git a/src/gui/kernel/qpalette.h b/src/gui/kernel/qpalette.h index 776d489d44..8525ae8af4 100644 --- a/src/gui/kernel/qpalette.h +++ b/src/gui/kernel/qpalette.h @@ -74,8 +74,8 @@ public: void swap(QPalette &other) noexcept { - qSwap(currentGroup, other.currentGroup); - qSwap(d, other.d); + std::swap(currentGroup, other.currentGroup); + qt_ptr_swap(d, other.d); } operator QVariant() const; diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index b5bdd9fb24..fb97284c4f 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -83,7 +83,7 @@ public: QBrush &operator=(const QBrush &brush); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QBrush) inline void swap(QBrush &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } operator QVariant() const; diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h index 43ae2257c0..59deca3a28 100644 --- a/src/gui/painting/qcolorspace.h +++ b/src/gui/painting/qcolorspace.h @@ -112,7 +112,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QColorSpace) void swap(QColorSpace &colorSpace) noexcept - { qSwap(d_ptr, colorSpace.d_ptr); } + { d_ptr.swap(colorSpace.d_ptr); } Primaries primaries() const noexcept; TransferFunction transferFunction() const noexcept; diff --git a/src/gui/painting/qpagelayout.h b/src/gui/painting/qpagelayout.h index 469436ce59..8d45241106 100644 --- a/src/gui/painting/qpagelayout.h +++ b/src/gui/painting/qpagelayout.h @@ -85,7 +85,7 @@ public: QPageLayout &operator=(const QPageLayout &other); ~QPageLayout(); - void swap(QPageLayout &other) noexcept { qSwap(d, other.d); } + void swap(QPageLayout &other) noexcept { d.swap(other.d); } bool isEquivalentTo(const QPageLayout &other) const; diff --git a/src/gui/painting/qpageranges.h b/src/gui/painting/qpageranges.h index d525124a62..11a30a95a5 100644 --- a/src/gui/painting/qpageranges.h +++ b/src/gui/painting/qpageranges.h @@ -65,7 +65,7 @@ public: QPageRanges(QPageRanges &&other) noexcept = default; QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPageRanges) void swap(QPageRanges &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } friend bool operator==(const QPageRanges &lhs, const QPageRanges &rhs) noexcept { return lhs.isEqual(rhs); } diff --git a/src/gui/painting/qpagesize.h b/src/gui/painting/qpagesize.h index f4e7af0f6c..569008f166 100644 --- a/src/gui/painting/qpagesize.h +++ b/src/gui/painting/qpagesize.h @@ -237,7 +237,7 @@ public: ~QPageSize(); - void swap(QPageSize &other) noexcept { qSwap(d, other.d); } + void swap(QPageSize &other) noexcept { d.swap(other.d); } friend Q_GUI_EXPORT bool operator==(const QPageSize &lhs, const QPageSize &rhs); bool isEquivalentTo(const QPageSize &other) const; diff --git a/src/gui/painting/qpen.h b/src/gui/painting/qpen.h index db280c765b..326467ad6f 100644 --- a/src/gui/painting/qpen.h +++ b/src/gui/painting/qpen.h @@ -73,7 +73,7 @@ public: QPen(QPen &&other) noexcept : d(qExchange(other.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPen) - void swap(QPen &other) noexcept { qSwap(d, other.d); } + void swap(QPen &other) noexcept { qt_ptr_swap(d, other.d); } Qt::PenStyle style() const; void setStyle(Qt::PenStyle); diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h index 12a3a4e502..ab4c2112ad 100644 --- a/src/gui/painting/qregion.h +++ b/src/gui/painting/qregion.h @@ -75,7 +75,7 @@ public: ~QRegion(); QRegion &operator=(const QRegion &); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QRegion) - inline void swap(QRegion &other) noexcept { qSwap(d, other.d); } + void swap(QRegion &other) noexcept { qt_ptr_swap(d, other.d); } bool isEmpty() const; bool isNull() const; diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index 1e1b97667f..2b8b93c0bb 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -174,8 +174,8 @@ public: QFont(const QFont &font); ~QFont(); - void swap(QFont &other) - { qSwap(d, other.d); qSwap(resolve_mask, other.resolve_mask); } + void swap(QFont &other) noexcept + { d.swap(other.d); std::swap(resolve_mask, other.resolve_mask); } QString family() const; void setFamily(const QString &); diff --git a/src/gui/text/qfontinfo.h b/src/gui/text/qfontinfo.h index ed889c2fb5..349daa3f84 100644 --- a/src/gui/text/qfontinfo.h +++ b/src/gui/text/qfontinfo.h @@ -56,7 +56,7 @@ public: QFontInfo &operator=(const QFontInfo &); - void swap(QFontInfo &other) { qSwap(d, other.d); } + void swap(QFontInfo &other) noexcept { d.swap(other.d); } QString family() const; QString styleName() const; diff --git a/src/gui/text/qfontmetrics.h b/src/gui/text/qfontmetrics.h index cd438fff7c..dc32317e15 100644 --- a/src/gui/text/qfontmetrics.h +++ b/src/gui/text/qfontmetrics.h @@ -64,7 +64,7 @@ public: QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetrics) void swap(QFontMetrics &other) noexcept - { qSwap(d, other.d); } + { d.swap(other.d); } int ascent() const; int capHeight() const; @@ -136,7 +136,7 @@ public: QFontMetricsF &operator=(const QFontMetrics &); QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QFontMetricsF) - void swap(QFontMetricsF &other) noexcept { qSwap(d, other.d); } + void swap(QFontMetricsF &other) noexcept { d.swap(other.d); } qreal ascent() const; qreal capHeight() const; diff --git a/src/gui/text/qglyphrun.h b/src/gui/text/qglyphrun.h index 0e9f0ce468..7ea47fdb21 100644 --- a/src/gui/text/qglyphrun.h +++ b/src/gui/text/qglyphrun.h @@ -70,7 +70,7 @@ public: QGlyphRun &operator=(const QGlyphRun &other); ~QGlyphRun(); - void swap(QGlyphRun &other) noexcept { qSwap(d, other.d); } + void swap(QGlyphRun &other) noexcept { d.swap(other.d); } QRawFont rawFont() const; void setRawFont(const QRawFont &rawFont); diff --git a/src/gui/text/qrawfont.h b/src/gui/text/qrawfont.h index 51f7ba8044..2e1aaa6da4 100644 --- a/src/gui/text/qrawfont.h +++ b/src/gui/text/qrawfont.h @@ -83,7 +83,7 @@ public: QRawFont &operator=(const QRawFont &other); ~QRawFont(); - void swap(QRawFont &other) noexcept { qSwap(d, other.d); } + void swap(QRawFont &other) noexcept { d.swap(other.d); } bool isValid() const; diff --git a/src/gui/text/qstatictext.h b/src/gui/text/qstatictext.h index 778861ed79..aafc43ed56 100644 --- a/src/gui/text/qstatictext.h +++ b/src/gui/text/qstatictext.h @@ -68,7 +68,7 @@ public: QStaticText &operator=(const QStaticText &); ~QStaticText(); - void swap(QStaticText &other) noexcept { qSwap(data, other.data); } + void swap(QStaticText &other) noexcept { data.swap(other.data); } void setText(const QString &text); QString text() const; diff --git a/src/gui/text/qtextcursor.h b/src/gui/text/qtextcursor.h index 59b32e0874..b33b05aacc 100644 --- a/src/gui/text/qtextcursor.h +++ b/src/gui/text/qtextcursor.h @@ -77,7 +77,7 @@ public: QTextCursor &operator=(const QTextCursor &other); ~QTextCursor(); - void swap(QTextCursor &other) noexcept { qSwap(d, other.d); } + void swap(QTextCursor &other) noexcept { d.swap(other.d); } bool isNull() const; diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index e8ebe75899..91f76e9987 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -320,7 +320,7 @@ public: ~QTextFormat(); void swap(QTextFormat &other) - { qSwap(d, other.d); qSwap(format_type, other.format_type); } + { d.swap(other.d); std::swap(format_type, other.format_type); } void merge(const QTextFormat &other); -- cgit v1.2.3