diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-10-20 14:12:55 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2009-10-20 15:12:21 (GMT) |
commit | ed2ff6553ec481bd489df096d5ec1cdb545ebb33 (patch) | |
tree | 3ce2ace54991380eea71ca5d2efeef8c03e575c3 /src | |
parent | a6b0316c2418a90cb754132a678c38027009e875 (diff) | |
download | Qt-ed2ff6553ec481bd489df096d5ec1cdb545ebb33.zip Qt-ed2ff6553ec481bd489df096d5ec1cdb545ebb33.tar.gz Qt-ed2ff6553ec481bd489df096d5ec1cdb545ebb33.tar.bz2 |
Optimization in qt_closestItemFirst private function
No need to traverse the tree again to access the topLevelItem in case
there is no common ancestor.
Reviewed-by: bnilsen
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 38145ac..8621b11 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -662,19 +662,18 @@ inline bool qt_closestItemFirst(const QGraphicsItem *item1, const QGraphicsItem } // item1Ancestor is now at the same level as item2Ancestor, but not the same. - const QGraphicsItem *a1 = t1; - const QGraphicsItem *a2 = t2; - while (a1) { - const QGraphicsItem *p1 = a1; - const QGraphicsItem *p2 = a2; - a1 = a1->parentItem(); - a2 = a2->parentItem(); - if (a1 && a1 == a2) - return qt_closestLeaf(p1, p2); + const QGraphicsItem *p1 = t1; + const QGraphicsItem *p2 = t2; + while (t1 && t1 != t2) { + p1 = t1; + p2 = t2; + t1 = t1->d_ptr->parent; + t2 = t2->d_ptr->parent; } - // No common ancestor? Then just compare the items' toplevels directly. - return qt_closestLeaf(t1->topLevelItem(), t2->topLevelItem()); + // in case we have a common ancestor, we compare the immediate children in the ancestor's path. + // otherwise we compare the respective items' topLevelItems directly. + return qt_closestLeaf(p1, p2); } /*! |