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>
This commit is contained in:
Konstantin Ritt 2015-11-21 00:34:43 +04:00
parent 0e99f3c853
commit 073a16e50e

View File

@ -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);