diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-03-15 23:05:06 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-03-15 23:21:39 (GMT) |
commit | ad70622193f8a34c28b6536521f8612e0b500fbf (patch) | |
tree | 9c4f113912c9c66669e50d359cb506700f8d2b9a /src | |
parent | 792978f693087dfecb1b9a6479e13ab75305d0d6 (diff) | |
download | Qt-ad70622193f8a34c28b6536521f8612e0b500fbf.zip Qt-ad70622193f8a34c28b6536521f8612e0b500fbf.tar.gz Qt-ad70622193f8a34c28b6536521f8612e0b500fbf.tar.bz2 |
Optimize QRegion::intersects(QRect).
Further optimize for the common case where numRects == 1. Benchmarks
included.
Reviewed-by: Samuel
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qregion.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp index bea2b6e..bfeef72 100644 --- a/src/gui/painting/qregion.cpp +++ b/src/gui/painting/qregion.cpp @@ -704,28 +704,13 @@ bool QRegion::intersects(const QRegion ®ion) const } /*! + \fn bool QRegion::intersects(const QRect &rect) const \since 4.2 Returns true if this region intersects with \a rect, otherwise returns false. */ -bool QRegion::intersects(const QRect &rect) const -{ - if (isEmpty() || rect.isNull()) - return false; - const QRect r = rect.normalized(); - if (!rect_intersects(boundingRect(), r)) - return false; - if (rectCount() == 1) - return true; - - const QVector<QRect> myRects = rects(); - for (QVector<QRect>::const_iterator it = myRects.constBegin(); it < myRects.constEnd(); ++it) - if (rect_intersects(r, *it)) - return true; - return false; -} #if !defined (Q_OS_UNIX) && !defined (Q_WS_WIN) /*! @@ -4349,5 +4334,24 @@ bool QRegion::operator==(const QRegion &r) const return EqualRegion(d->qt_rgn, r.d->qt_rgn); } +bool QRegion::intersects(const QRect &rect) const +{ + if (isEmptyHelper(d->qt_rgn) || rect.isNull()) + return false; + + const QRect r = rect.normalized(); + if (!rect_intersects(d->qt_rgn->extents, r)) + return false; + if (d->qt_rgn->numRects == 1) + return true; + + const QVector<QRect> myRects = rects(); + for (QVector<QRect>::const_iterator it = myRects.constBegin(); it < myRects.constEnd(); ++it) + if (rect_intersects(r, *it)) + return true; + return false; +} + + #endif QT_END_NAMESPACE |