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 <tatiana.borisova@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
c05982fda3
commit
d769ca41fc
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user