From e3e2e6877499ac6a151691e79d51850b9dad8941 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 30 Jul 2014 13:07:31 +0200 Subject: [PATCH] Micro-optimize QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint() QWidget::isVisible() is an inline call, but sizeHint() is a virtual function. Use QSize operations to call each one only once. Also reduces the number of q-> qualifications needed. It must be noted that this change is not entirely behavior-preserving: If sizeHint() returns a negative component, and the dialog is not visible, resize() will be called with that negative component now, instead of zero as was the case previously. I believe this is not a problem, because the way sizeHint() is currently implemented, the width cannot be less than 200 and for the height to be negative, the sum of label, bar and button size hint height would need to be negative, which is next to impossible. Change-Id: Ie8ba110e193532921eb4732a0393a377e38d7f7e Reviewed-by: David Faure Reviewed-by: Friedemann Kleint --- src/widgets/dialogs/qprogressdialog.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index 4a2b5cbea9..ed856c266e 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -505,9 +505,10 @@ void QProgressDialogPrivate::ensureSizeIsAtLeastSizeHint() { Q_Q(QProgressDialog); - int w = qMax(q->isVisible() ? q->width() : 0, q->sizeHint().width()); - int h = qMax(q->isVisible() ? q->height() : 0, q->sizeHint().height()); - q->resize(w, h); + QSize size = q->sizeHint(); + if (q->isVisible()) + size = size.expandedTo(q->size()); + q->resize(size); }