diff options
author | Marc Mutz <[email protected]> | 2025-01-29 11:40:07 +0100 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2025-01-30 15:33:19 +0100 |
commit | d769ca41fc11e1af81e4cdf7cacb3884f98b108c (patch) | |
tree | a3f9e8ccc9824022466d131efea0ccbbb8842078 | |
parent | c05982fda39bbfa9fa3641c7e5938f204a8b1bf5 (diff) |
QPen/QBrush: de-inline compare helper functions
These functions expose implementation details of their respective
class, so, seeing as the classes are pimpl'ed and their op==s are
out-of-line, too, these functions ought to be out-of-line, too.
De-inline them, by calling a private out-of-line helper function. This
way, they can remain unexported and "real" hidden friends (= with an
inline definition).
As drive-by:
- in QBrush/QColor: check the properties in the order of cheapness
(style(), color(), transform()), and don't copy QTransform just to
check isIdentity() (access the member directly).
- in QPen/QColor: avoid the QBrush copy (access the member
directly). This also retroactively endorses the noexcept on this
function.
- in QPen/PenStyle: amend the comment that says it's allocating with a
`// ### optimize`
Amends f0186862e16128343705abd0de5994e8ca05a909.
Found in API-review.
Pick-to: 6.9
Change-Id: Ibfd43b1f2200ef030d6739dad1bf026cc190606b
Reviewed-by: Tatiana Borisova <[email protected]>
Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r-- | src/gui/painting/qbrush.cpp | 27 | ||||
-rw-r--r-- | src/gui/painting/qbrush.h | 18 | ||||
-rw-r--r-- | src/gui/painting/qpen.cpp | 17 | ||||
-rw-r--r-- | src/gui/painting/qpen.h | 8 |
4 files changed, 52 insertions, 18 deletions
diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index b993261ac15..b2f1631f21c 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -974,6 +974,33 @@ bool QBrush::operator==(const QBrush &b) const } } +/*! + \internal +*/ +bool QBrush::doCompareEqualColor(QColor rhs) const noexcept +{ + return style() == Qt::SolidPattern && color() == rhs && d->transform.isIdentity(); +} + +/*! + \internal +*/ +bool QBrush::doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept +{ + switch (rhs) { + case Qt::NoBrush: + case Qt::TexturePattern: + case Qt::LinearGradientPattern: + case Qt::RadialGradientPattern: + case Qt::ConicalGradientPattern: + // A brush constructed only from one of those styles will end up + // using NoBrush (see qbrush_check_type) + return style() == Qt::NoBrush; + default: + return style() == rhs && color() == QColor(0, 0, 0); + } +} + #ifndef QT_NO_DEBUG_STREAM /*! \internal diff --git a/src/gui/painting/qbrush.h b/src/gui/painting/qbrush.h index 0a7dc6cf5d0..69ce983cc1a 100644 --- a/src/gui/painting/qbrush.h +++ b/src/gui/painting/qbrush.h @@ -86,28 +86,18 @@ private: friend class QPainter; friend bool Q_GUI_EXPORT qHasPixmapTexture(const QBrush& brush); + bool doCompareEqualColor(QColor rhs) const noexcept; friend bool comparesEqual(const QBrush &lhs, QColor rhs) noexcept { - return lhs.color() == rhs && lhs.style() == Qt::SolidPattern - && lhs.transform().isIdentity(); + return lhs.doCompareEqualColor(rhs); } Q_DECLARE_EQUALITY_COMPARABLE(QBrush, QColor) Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::GlobalColor) + bool doCompareEqualStyle(Qt::BrushStyle rhs) const noexcept; friend bool comparesEqual(const QBrush &lhs, Qt::BrushStyle rhs) noexcept { - switch (rhs) { - case Qt::NoBrush: - case Qt::TexturePattern: - case Qt::LinearGradientPattern: - case Qt::RadialGradientPattern: - case Qt::ConicalGradientPattern: - // A brush constructed only from one of those styles will end up - // using NoBrush (see qbrush_check_type) - return lhs.style() == Qt::NoBrush; - default: - return lhs.style() == rhs && lhs.color() == QColor(0, 0, 0); - } + return lhs.doCompareEqualStyle(rhs); } Q_DECLARE_EQUALITY_COMPARABLE(QBrush, Qt::BrushStyle) diff --git a/src/gui/painting/qpen.cpp b/src/gui/painting/qpen.cpp index fdab16ff0e4..d974c18728a 100644 --- a/src/gui/painting/qpen.cpp +++ b/src/gui/painting/qpen.cpp @@ -856,6 +856,23 @@ bool QPen::operator==(const QPen &p) const && p.d->cosmetic == d->cosmetic); } +/*! + \internal +*/ +bool QPen::doCompareEqualColor(QColor rhs) const noexcept +{ + return d->brush == rhs && isSolidDefaultLine(); +} + +/*! + \internal +*/ +bool QPen::doCompareEqualStyle(Qt::PenStyle rhs) const +{ + if (rhs == Qt::NoPen) + return style() == Qt::NoPen; + return *this == QPen(rhs); // ### optimize (allocates) +} /*! \fn bool QPen::isDetached() diff --git a/src/gui/painting/qpen.h b/src/gui/painting/qpen.h index 897ebfb8428..14a46415fa9 100644 --- a/src/gui/painting/qpen.h +++ b/src/gui/painting/qpen.h @@ -91,17 +91,17 @@ private: bool isSolidDefaultLine() const noexcept; + bool doCompareEqualColor(QColor rhs) const noexcept; friend bool comparesEqual(const QPen &lhs, QColor rhs) noexcept { - return lhs.brush() == rhs && lhs.isSolidDefaultLine(); + return lhs.doCompareEqualColor(rhs); } Q_DECLARE_EQUALITY_COMPARABLE(QPen, QColor) + bool doCompareEqualStyle(Qt::PenStyle rhs) const; friend bool comparesEqual(const QPen &lhs, Qt::PenStyle rhs) { - if (rhs == Qt::NoPen) - return lhs.style() == Qt::NoPen; - return lhs == QPen(rhs); // allocates + return lhs.doCompareEqualStyle(rhs); } Q_DECLARE_EQUALITY_COMPARABLE_NON_NOEXCEPT(QPen, Qt::PenStyle) |