Fix performance regression when avoiding scrollbar flipping

Amends 6c4dc722cb9bf765904feefff4fb00bdb0b3dc9f.

Don't search for the optimal size of the scrollarea's widget if it can't
be found anyway. Try the size with scrollbar first, which covers the
vast majority of sizes.

Optimizing the loop with e.g. a binary search adds no value, as the size
is often just a pixel too small.

Since we can't rely on the number of height-for-width calls, we can't
meaningfully test this behavior. The number of calls is still very high
during showing and resizing; optimizing this further is for a separate
commit.

Fixes: QTBUG-97811
Pick-to: 6.2 5.15
Change-Id: If145302e6414b32cf1ce7251ff33b0039f584867
Reviewed-by: Jonas Kvinge <jonas@jkvinge.net>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-10-28 16:55:33 +02:00
parent 53ffa665d0
commit ffc9323671

View File

@ -203,10 +203,13 @@ void QScrollAreaPrivate::updateScrollBars()
if (vbarpolicy == Qt::ScrollBarAsNeeded) {
int vbarWidth = vbar->sizeHint().width();
QSize m_hfw = m.expandedTo(min).boundedTo(max);
while (h > m.height() && vbarWidth) {
--vbarWidth;
--m_hfw.rwidth();
h = widget->heightForWidth(m_hfw.width());
// is there any point in searching?
if (widget->heightForWidth(m_hfw.width() - vbarWidth) <= m.height()) {
while (h > m.height() && vbarWidth) {
--vbarWidth;
--m_hfw.rwidth();
h = widget->heightForWidth(m_hfw.width());
}
}
max = QSize(m_hfw.width(), qMax(m_hfw.height(), h));
}