From 909e6a009c968042f5295358737c9d2d84fcc0ba Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 3 Dec 2015 14:33:42 +0100 Subject: [PATCH] Clean up QGraphicsItemCache::purge() The old code assigned an empty QPoint to elements contained by value in a QHash that was cleared out in the very next step. That makes no sense, because the operations in the loop cannot possibly cause a re-entrancy into QGraphicsItemCache, which would be the only explanation for modifying the state of a death-row object. While at it, replace the use of the highly inefficient (and no longer needed) QMutableHashIterator with C++11 range-for, taking care to iterate over a const reference to avoid detaches. Change-Id: Ie3eba0f954644a27932666bc9e97f1ca8f36a578 Reviewed-by: Friedemann Kleint --- src/widgets/graphicsview/qgraphicsitem.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index 5f5c402a4a..54a98b4d2d 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -1373,12 +1373,9 @@ void QGraphicsItemCache::purge() { QPixmapCache::remove(key); key = QPixmapCache::Key(); - QMutableHashIterator it(deviceData); - while (it.hasNext()) { - DeviceData &data = it.next().value(); + const auto &constDeviceData = deviceData; // avoid detach + for (const auto &data : constDeviceData) QPixmapCache::remove(data.key); - data.cacheIndent = QPoint(); - } deviceData.clear(); allExposed = true; exposed.clear();