From 2e1e1cff3696c93f983db78c99e564a791d5d0ef Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 1 Jun 2010 09:39:57 +0200 Subject: Avoid unnecessary detach / deep copy in QGraphicsItem::scroll(). QGraphicsItem::scroll() scrolls the cache pixmap when cacheMode is enabled (for ItemCoordinateCache only). Because the pixmap exists both in the cache and in a temp QPixmap copy, the ref count is 2, so the scroll operation has to do a deep copy. To avoid this, we remove the pixmap from the cache before and reinsert it again after calling QPixmap::scroll(). Reviewed-by: Alexis Menard --- src/gui/graphicsview/qgraphicsitem.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 36d21a6..d284a29 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -5687,11 +5687,13 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) return; } + // Find pixmap in cache, then remove to avoid deep copy when modifying.s QPixmap cachedPixmap; if (!QPixmapCache::find(cache->key, &cachedPixmap)) { update(rect); return; } + QPixmapCache::remove(cache->key); QRegion exposed; const bool scrollEntirePixmap = rect.isNull(); @@ -5707,7 +5709,8 @@ void QGraphicsItem::scroll(qreal dx, qreal dy, const QRectF &rect) cachedPixmap.scroll(dx, dy, scrollRect.translated(-cache->boundingRect.topLeft()), &exposed); } - QPixmapCache::replace(cache->key, cachedPixmap); + // Reinsert into cache. + cache->key = QPixmapCache::insert(cachedPixmap); // Translate the existing expose. for (int i = 0; i < cache->exposed.size(); ++i) { -- cgit v0.12