QBrush: optimize detach()

Previously, detach() would detach on every style change. But there
are only three QBrushData classes, thus many styles use the same.

So instead of checking for style identity, check for style equivalence,
where equivalence is defined in terms of use_same_brushdata().

Change-Id: I7548c6022a45e542ca0d3ea00d837cd4ff93df34
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
This commit is contained in:
Marc Mutz 2014-08-29 10:18:04 +02:00
parent 0ec512e90b
commit daab9e38c3

View File

@ -569,11 +569,20 @@ void QBrush::cleanUp(QBrushData *x)
QBrushDataPointerDeleter::deleteData(x);
}
static Q_DECL_CONSTEXPR inline bool use_same_brushdata(Qt::BrushStyle lhs, Qt::BrushStyle rhs)
{
return lhs == rhs // includes Qt::TexturePattern
|| (lhs >= Qt::NoBrush && lhs <= Qt::DiagCrossPattern && rhs >= Qt::NoBrush && rhs <= Qt::DiagCrossPattern)
|| (lhs >= Qt::LinearGradientPattern && lhs <= Qt::ConicalGradientPattern && rhs >= Qt::LinearGradientPattern && rhs <= Qt::ConicalGradientPattern)
;
}
void QBrush::detach(Qt::BrushStyle newStyle)
{
if (newStyle == d->style && d->ref.load() == 1)
if (use_same_brushdata(newStyle, d->style) && d->ref.load() == 1) {
d->style = newStyle;
return;
}
QScopedPointer<QBrushData> x;
switch(newStyle) {