summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextlayout.cpp
diff options
context:
space:
mode:
authorKonstantin Ritt <ritt.ks@gmail.com>2015-11-21 00:34:43 +0400
committerKonstantin Ritt <ritt.ks@gmail.com>2015-11-23 18:52:43 +0000
commit073a16e50e5803fc92dc46bca704f8a7ef79e597 (patch)
treec0a64987c1a937cada29c204c413f99c2f030c89 /src/gui/text/qtextlayout.cpp
parent0e99f3c853aa10f60aa33804c122b187edb565ea (diff)
QTextLine::cursorToX: Optimize by re-using the cached values
(and move some code around) Change-Id: I2e26dcc7b769fdbcc750332845da11ec88e332dd Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/gui/text/qtextlayout.cpp')
-rw-r--r--src/gui/text/qtextlayout.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index e69a591d59..67af3d316b 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -2663,18 +2663,14 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
const QScriptItem *si = &eng->layoutData->items[itm];
if (!si->num_glyphs)
eng->shape(itm);
- pos -= si->position;
+
+ const int l = eng->length(itm);
+ pos = qBound(0, pos - si->position, l);
QGlyphLayout glyphs = eng->shapedGlyphs(si);
unsigned short *logClusters = eng->logClusters(si);
Q_ASSERT(logClusters);
- int l = eng->length(itm);
- if (pos > l)
- pos = l;
- if (pos < 0)
- pos = 0;
-
int glyph_pos = pos == l ? si->num_glyphs : logClusters[pos];
if (edge == Trailing && glyph_pos < si->num_glyphs) {
// trailing edge is leading edge of next cluster
@@ -2683,7 +2679,7 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
glyph_pos++;
}
- bool reverse = eng->layoutData->items[itm].analysis.bidiLevel % 2;
+ bool reverse = si->analysis.bidiLevel % 2;
// add the items left of the cursor
@@ -2710,13 +2706,15 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
x += si.width;
continue;
}
+
+ const int itemLength = eng->length(item);
int start = qMax(line.from, si.position);
- int end = qMin(lineEnd, si.position + eng->length(item));
+ int end = qMin(lineEnd, si.position + itemLength);
logClusters = eng->logClusters(&si);
int gs = logClusters[start-si.position];
- int ge = (end == si.position + eng->length(item)) ? si.num_glyphs-1 : logClusters[end-si.position-1];
+ int ge = (end == si.position + itemLength) ? si.num_glyphs-1 : logClusters[end-si.position-1];
QGlyphLayout glyphs = eng->shapedGlyphs(&si);