From cb3e1e551f340ce1e6280123d8b5411b3c1c96d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 15 Aug 2019 14:42:12 +0200 Subject: QWidgetBackingStore: clean up around dirtyOnScreenWidgets The QVector dirtyOnScreenWidgets was aggregated by pointer, which makes no sense, as a QVector is just as large as a pointer (and even in Qt 6, when it will be larger, it's not going to be horrible). But this complicated the code quite a bit. Aggregate by value instead (it's just one of three such vectors now). Drive-by fixes: - use QVector::removeAll() instead of rolling your own - port two indexed loops to ranged ones. In the first case, it's safe, as the loop body clearly doesn't touch the iteratee (it's just a std::accumulate). In the second, the question no longer applies, as we're now using a consume loop. Change-Id: Icd4ac13bb4a6f9a783f0adf2fb6a5bdfacd1f91a Reviewed-by: Friedemann Kleint Reviewed-by: Volker Hilsheimer --- src/widgets/kernel/qwidgetbackingstore.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/widgets/kernel/qwidgetbackingstore.cpp') diff --git a/src/widgets/kernel/qwidgetbackingstore.cpp b/src/widgets/kernel/qwidgetbackingstore.cpp index 8b0094a93c..009ffb17a1 100644 --- a/src/widgets/kernel/qwidgetbackingstore.cpp +++ b/src/widgets/kernel/qwidgetbackingstore.cpp @@ -397,15 +397,12 @@ QRegion QWidgetBackingStore::dirtyRegion(QWidget *widget) const // Append the region that needs flush. r += dirtyOnScreen; - if (dirtyOnScreenWidgets) { // Only in use with native child widgets. - for (int i = 0; i < dirtyOnScreenWidgets->size(); ++i) { - QWidget *w = dirtyOnScreenWidgets->at(i); - if (widgetDirty && w != widget && !widget->isAncestorOf(w)) - continue; - QWidgetPrivate *wd = w->d_func(); - Q_ASSERT(wd->needsFlush); - r += wd->needsFlush->translated(w->mapTo(tlw, QPoint())); - } + for (QWidget *w : dirtyOnScreenWidgets) { + if (widgetDirty && w != widget && !widget->isAncestorOf(w)) + continue; + QWidgetPrivate *wd = w->d_func(); + Q_ASSERT(wd->needsFlush); + r += wd->needsFlush->translated(w->mapTo(tlw, QPoint())); } if (widgetDirty) { @@ -686,8 +683,8 @@ void QWidgetBackingStore::removeDirtyWidget(QWidget *w) if (!w) return; - dirtyWidgetsRemoveAll(w); - dirtyOnScreenWidgetsRemoveAll(w); + dirtyWidgets.removeAll(w); + dirtyOnScreenWidgets.removeAll(w); dirtyRenderToTextureWidgets.removeAll(w); resetWidget(w); @@ -719,7 +716,6 @@ void QWidgetBackingStore::updateLists(QWidget *cur) QWidgetBackingStore::QWidgetBackingStore(QWidget *topLevel) : tlw(topLevel), - dirtyOnScreenWidgets(0), updateRequestSent(0), textureListWatcher(0), perfFrames(0) @@ -737,8 +733,6 @@ QWidgetBackingStore::~QWidgetBackingStore() resetWidget(dirtyWidgets.at(c)); for (int c = 0; c < dirtyRenderToTextureWidgets.size(); ++c) resetWidget(dirtyRenderToTextureWidgets.at(c)); - - delete dirtyOnScreenWidgets; } static QVector getSortedRectsToScroll(const QRegion ®ion, int dx, int dy) @@ -1373,7 +1367,7 @@ void QWidgetBackingStore::doSync() */ void QWidgetBackingStore::flush(QWidget *widget) { - const bool hasDirtyOnScreenWidgets = dirtyOnScreenWidgets && !dirtyOnScreenWidgets->isEmpty(); + const bool hasDirtyOnScreenWidgets = !dirtyOnScreenWidgets.isEmpty(); bool flushed = false; // Flush the region in dirtyOnScreen. @@ -1400,15 +1394,13 @@ void QWidgetBackingStore::flush(QWidget *widget) if (!hasDirtyOnScreenWidgets) return; - for (int i = 0; i < dirtyOnScreenWidgets->size(); ++i) { - QWidget *w = dirtyOnScreenWidgets->at(i); + for (QWidget *w : qExchange(dirtyOnScreenWidgets, {})) { QWidgetPrivate *wd = w->d_func(); Q_ASSERT(wd->needsFlush); QPlatformTextureList *widgetTexturesForNative = wd->textureChildSeen ? widgetTexturesFor(tlw, w) : 0; qt_flush(w, *wd->needsFlush, store, tlw, widgetTexturesForNative, this); *wd->needsFlush = QRegion(); } - dirtyOnScreenWidgets->clear(); } /*! -- cgit v1.2.3