diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-08 13:08:14 +0300 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-10 08:28:53 +0000 |
commit | 963695b4907f59f5b12699b3dd66fc665762616a (patch) | |
tree | 33840a78d663d91f99141742a74bbc1d102986c3 /src/quickcontrols2/qquickiconlabel.cpp | |
parent | 82e580bb91ebdde590d4f9beec242352918ce617 (diff) |
Micro-optimize QQuickIconLabel
Reduce indirection between the public and private objects. Things like
width, height, and componentComplete can be accessed directly in the
private object instead of asking them from the public object, which in
turn asks them from the private object. Furthermore, when direct access
is available on the stack, reference directly instead of repeatedly via
the d-ptr.
Change-Id: Idbb40bc86ebff7b7b22e21050941afd6f0027bfe
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quickcontrols2/qquickiconlabel.cpp')
-rw-r--r-- | src/quickcontrols2/qquickiconlabel.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/quickcontrols2/qquickiconlabel.cpp b/src/quickcontrols2/qquickiconlabel.cpp index f2d069ab..476d7808 100644 --- a/src/quickcontrols2/qquickiconlabel.cpp +++ b/src/quickcontrols2/qquickiconlabel.cpp @@ -57,7 +57,7 @@ QQuickIconLabelPrivate::QQuickIconLabelPrivate() void QQuickIconLabelPrivate::updateImplicitSize() { Q_Q(QQuickIconLabel); - if (!q->isComponentComplete()) + if (!componentComplete) return; const bool showIcon = icon && display != QQuickIconLabel::TextOnly; @@ -76,18 +76,15 @@ void QQuickIconLabelPrivate::updateImplicitSize() void QQuickIconLabelPrivate::layout() { - Q_Q(QQuickIconLabel); - if (!q->isComponentComplete()) + if (!componentComplete) return; const qreal horizontalPadding = leftPadding + rightPadding; const qreal verticalPadding = topPadding + bottomPadding; - const qreal w = q->width(); - const qreal h = q->height(); - const qreal availableWidth = w - horizontalPadding; - const qreal availableHeight = h - verticalPadding; - const qreal horizontalCenter = w / 2; - const qreal verticalCenter = h / 2; + const qreal availableWidth = width - horizontalPadding; + const qreal availableHeight = height - verticalPadding; + const qreal horizontalCenter = width / 2; + const qreal verticalCenter = height / 2; switch (display) { case QQuickIconLabel::IconOnly: @@ -215,9 +212,9 @@ void QQuickIconLabel::setIcon(QQuickItem *icon) d->unwatchChanges(d->icon); d->icon = icon; - if (d->icon) { - d->icon->setParentItem(this); - d->watchChanges(d->icon); + if (icon) { + icon->setParentItem(this); + d->watchChanges(icon); } d->updateImplicitSize(); @@ -240,9 +237,9 @@ void QQuickIconLabel::setLabel(QQuickItem *label) d->unwatchChanges(d->label); d->label = label; - if (d->label) { - d->label->setParentItem(this); - d->watchChanges(d->label); + if (label) { + label->setParentItem(this); + d->watchChanges(label); } d->updateImplicitSize(); |