summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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