summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2012-07-19 12:42:37 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-08-31 20:21:28 (GMT)
commit1dddfaa82cadd782366ba7dc9d0995b6c9865a24 (patch)
tree427020ab4f475764a47761ce751f0f5b4ff4979e /src
parent49fbb6e14af78f751fa114c3cf986aaa607d7408 (diff)
downloadQt-1dddfaa82cadd782366ba7dc9d0995b6c9865a24.zip
Qt-1dddfaa82cadd782366ba7dc9d0995b6c9865a24.tar.gz
Qt-1dddfaa82cadd782366ba7dc9d0995b6c9865a24.tar.bz2
Speed up QTextEngine::setBoundary
Before, setBoundary was O(N), now it is O(log N) assuming the boundaries are added in order. (splitItem might still be linear because of the call to QVector::insert) This speeds up a lot QTextEngine::addRequiredBoundaries when there is a lot of addFormats. (For example if there is a very long line with syntax highlighting) Task-number: QTBUG-8389 Change-Id: I10c9fca72343f46db24b1d4f519f7747188d4009 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> (cherry picked from commit c13011829fd39661cc9e983256766c6edb88dead)
Diffstat (limited to 'src')
-rw-r--r--src/gui/text/qtextengine.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index fbaf71f..3af0355 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2643,20 +2643,28 @@ QString QTextEngine::elidedText(Qt::TextElideMode mode, const QFixed &width, int
return layoutData->string;
}
+namespace {
+struct QScriptItemComparator {
+ bool operator()(const QScriptItem &a, const QScriptItem &b) { return a.position < b.position; }
+ bool operator()(int p, const QScriptItem &b) { return p < b.position; }
+ //bool operator()(const QScriptItem &a, int p) { return a.position < p; }
+};
+}
+
void QTextEngine::setBoundary(int strPos) const
{
if (strPos <= 0 || strPos >= layoutData->string.length())
return;
- int itemToSplit = 0;
- while (itemToSplit < layoutData->items.size() && layoutData->items.at(itemToSplit).position <= strPos)
- itemToSplit++;
- itemToSplit--;
- if (layoutData->items.at(itemToSplit).position == strPos) {
+ const QScriptItem* it = qUpperBound(layoutData->items.constBegin(), layoutData->items.constEnd(),
+ strPos, QScriptItemComparator());
+ Q_ASSERT(it > layoutData->items.constBegin());
+ --it;
+ if (it->position == strPos) {
// already a split at the requested position
return;
}
- splitItem(itemToSplit, strPos - layoutData->items.at(itemToSplit).position);
+ splitItem(it - layoutData->items.constBegin(), strPos - it->position);
}
void QTextEngine::splitItem(int item, int pos) const