summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorSteffen Hansen <steffen@kdab.com>2011-04-20 10:45:42 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2011-04-21 09:44:06 (GMT)
commit8e1fd720f61c6704050d731a1e6b0a31cd7706bd (patch)
treed76799878ecaecf7eaf7a825329a067a433427fd /src/gui/text
parent4c8c5ef3866723124fe8cf2c8bdd3b846549b129 (diff)
downloadQt-8e1fd720f61c6704050d731a1e6b0a31cd7706bd.zip
Qt-8e1fd720f61c6704050d731a1e6b0a31cd7706bd.tar.gz
Qt-8e1fd720f61c6704050d731a1e6b0a31cd7706bd.tar.bz2
Use binary search to speed up findChildFrame()
Merge-request: 2595 Reviewed-by: mae
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextdocument_p.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gui/text/qtextdocument_p.cpp b/src/gui/text/qtextdocument_p.cpp
index 2172f74..a997720 100644
--- a/src/gui/text/qtextdocument_p.cpp
+++ b/src/gui/text/qtextdocument_p.cpp
@@ -1406,11 +1406,18 @@ void QTextDocumentPrivate::changeObjectFormat(QTextObject *obj, int format)
static QTextFrame *findChildFrame(QTextFrame *f, int pos)
{
- // ##### use binary search
- QList<QTextFrame *> children = f->childFrames();
- for (int i = 0; i < children.size(); ++i) {
- QTextFrame *c = children.at(i);
- if (pos >= c->firstPosition() && pos <= c->lastPosition())
+ /* Binary search for frame at pos */
+ const QList<QTextFrame *> children = f->childFrames();
+ int first = 0;
+ int last = children.size() - 1;
+ while (first <= last) {
+ int mid = (first + last) / 2;
+ QTextFrame *c = children.at(mid);
+ if (pos > c->lastPosition())
+ first = mid + 1;
+ else if (pos < c->firstPosition())
+ last = mid - 1;
+ else
return c;
}
return 0;