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 <Friedemann.Kleint@theqtcompany.com>
bb10
Marc Mutz 2015-12-03 14:33:42 +01:00
parent 6b1dc2641e
commit 909e6a009c
1 changed files with 2 additions and 5 deletions

View File

@ -1373,12 +1373,9 @@ void QGraphicsItemCache::purge()
{
QPixmapCache::remove(key);
key = QPixmapCache::Key();
QMutableHashIterator<QPaintDevice *, DeviceData> 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();