diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-06-02 11:50:28 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-06-09 07:30:54 (GMT) |
commit | d44332954b2a8e66ba4129c230e8ccc65fd972ea (patch) | |
tree | 328f167af5d4b8e66683e820306695c2bf102845 | |
parent | 1b78999dcd5512ce46e2fac20811ad63f3e93ec0 (diff) | |
download | Qt-d44332954b2a8e66ba4129c230e8ccc65fd972ea.zip Qt-d44332954b2a8e66ba4129c230e8ccc65fd972ea.tar.gz Qt-d44332954b2a8e66ba4129c230e8ccc65fd972ea.tar.bz2 |
Don't construct new style option objects in a tight loop.
The QStyleOption constructor is expensive, as it allocates a QFont,
a QPalette and a QFontMetrics. By simply reusing a temporary style
option object instead we carve away wasted cycles.
Reviewed-by: Ariya
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 17 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene_p.h | 3 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index eac057e..0c679de 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4763,7 +4763,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte // Generate the item's exposedRect and map its list of expose // rects to device coordinates. - QStyleOptionGraphicsItem cacheOption = *option; + styleOptionTmp = *option; QRegion pixmapExposed; QRectF exposedRect; if (!itemCache->allExposed) { @@ -4775,11 +4775,11 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte } else { exposedRect = brect; } - cacheOption.exposedRect = exposedRect; + styleOptionTmp.exposedRect = exposedRect; // Render. _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), - &cacheOption, painterStateProtection); + &styleOptionTmp, painterStateProtection); // insert this pixmap into the cache. itemCache->key = QPixmapCache::insert(pix); @@ -4940,12 +4940,12 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte foreach (QRect r, scrollExposure.rects()) br |= pixmapToItem.mapRect(r); } - QStyleOptionGraphicsItem cacheOption = *option; - cacheOption.exposedRect = br.adjusted(-1, -1, 1, 1); + styleOptionTmp = *option; + styleOptionTmp.exposedRect = br.adjusted(-1, -1, 1, 1); // Render the exposed areas. _q_paintIntoCache(&pix, item, pixmapExposed, itemToPixmap, painter->renderHints(), - &cacheOption, painterStateProtection); + &styleOptionTmp, painterStateProtection); // Reset expose data. pixModified = true; @@ -5062,8 +5062,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * // Draw item if (!dontDrawItem) { - QStyleOptionGraphicsItem option; - item->d_ptr->initStyleOption(&option, transform, exposedRegion ? *exposedRegion : QRegion(), exposedRegion == 0); + item->d_ptr->initStyleOption(&styleOptionTmp, transform, exposedRegion ? *exposedRegion : QRegion(), exposedRegion == 0); bool clipsToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsToShape); bool savePainter = clipsToShape || !(optimizationFlags & QGraphicsView::DontSavePainterState); @@ -5074,7 +5073,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * if (clipsToShape) painter->setClipPath(item->shape(), Qt::IntersectClip); painter->setOpacity(opacity); - drawItemHelper(item, painter, &option, widget, false); + drawItemHelper(item, painter, &styleOptionTmp, widget, false); if (savePainter) painter->restore(); diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h index 9e9ef6b..d74591c 100644 --- a/src/gui/graphicsview/qgraphicsscene_p.h +++ b/src/gui/graphicsview/qgraphicsscene_p.h @@ -69,6 +69,7 @@ #include <QtGui/qfont.h> #include <QtGui/qpalette.h> #include <QtGui/qstyle.h> +#include <QtGui/qstyleoption.h> QT_BEGIN_NAMESPACE @@ -281,6 +282,8 @@ public: void setPalette_helper(const QPalette &palette); void resolvePalette(); void updatePalette(const QPalette &palette); + + QStyleOptionGraphicsItem styleOptionTmp; }; QT_END_NAMESPACE |