Minor optimization for QTextLineItemIterator
Don't store unused values (pos_x and levels) and re-use already calculated ones (itemStart, itemEnd, and itemLength). Also const-ify some members to make the code a bit more clear. Change-Id: Ied80ebf9e4e7e8a1d057e413a9bd24f84b8aaf92 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
7952cf7e27
commit
4689a9b3f0
@ -3478,15 +3478,15 @@ QTextLineItemIterator::QTextLineItemIterator(QTextEngine *_eng, int _lineNum, co
|
||||
logicalItem(-1),
|
||||
item(-1),
|
||||
visualOrder(nItems),
|
||||
levels(nItems),
|
||||
selection(_selection)
|
||||
{
|
||||
pos_x = x = QFixed::fromReal(pos.x());
|
||||
x = QFixed::fromReal(pos.x());
|
||||
|
||||
x += line.x;
|
||||
|
||||
x += eng->alignLine(line);
|
||||
|
||||
QVarLengthArray<uchar> levels(nItems);
|
||||
for (int i = 0; i < nItems; ++i)
|
||||
levels[i] = eng->layoutData->items[i+firstItem].analysis.bidiLevel;
|
||||
QTextEngine::bidiReorder(nItems, levels.data(), visualOrder.data());
|
||||
@ -3557,7 +3557,7 @@ bool QTextLineItemIterator::getSelectionBounds(QFixed *selectionX, QFixed *selec
|
||||
return false;
|
||||
|
||||
int start_glyph = logClusters[from];
|
||||
int end_glyph = (to == eng->length(item)) ? si->num_glyphs : logClusters[to];
|
||||
int end_glyph = (to == itemLength) ? si->num_glyphs : logClusters[to];
|
||||
QFixed soff;
|
||||
QFixed swidth;
|
||||
if (si->analysis.bidiLevel %2) {
|
||||
@ -3582,7 +3582,7 @@ bool QTextLineItemIterator::getSelectionBounds(QFixed *selectionX, QFixed *selec
|
||||
// If the ending character is also part of a ligature, swidth does
|
||||
// not contain that part yet, we also need to find out the width of
|
||||
// that left part
|
||||
*selectionWidth += eng->offsetInLigature(si, to, eng->length(item), end_glyph);
|
||||
*selectionWidth += eng->offsetInLigature(si, to, itemLength, end_glyph);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -676,15 +676,14 @@ struct QTextLineItemIterator
|
||||
QTextEngine *eng;
|
||||
|
||||
QFixed x;
|
||||
QFixed pos_x;
|
||||
const QScriptLine &line;
|
||||
QScriptItem *si;
|
||||
|
||||
int lineNum;
|
||||
int lineEnd;
|
||||
int firstItem;
|
||||
int lastItem;
|
||||
int nItems;
|
||||
const int lineNum;
|
||||
const int lineEnd;
|
||||
const int firstItem;
|
||||
const int lastItem;
|
||||
const int nItems;
|
||||
int logicalItem;
|
||||
int item;
|
||||
int itemLength;
|
||||
@ -697,7 +696,6 @@ struct QTextLineItemIterator
|
||||
QFixed itemWidth;
|
||||
|
||||
QVarLengthArray<int> visualOrder;
|
||||
QVarLengthArray<uchar> levels;
|
||||
|
||||
const QTextLayout::FormatRange *selection;
|
||||
};
|
||||
|
@ -2198,14 +2198,10 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
|
||||
if (si.analysis.flags >= QScriptAnalysis::TabOrObject)
|
||||
continue;
|
||||
|
||||
QPointF pos(iterator.x.toReal(), y);
|
||||
if (from >= 0 && length >= 0 &&
|
||||
(from >= si.position + eng->length(&si)
|
||||
|| from + length <= si.position
|
||||
|| from + length <= iterator.itemStart
|
||||
|| from >= iterator.itemEnd)) {
|
||||
if (from >= 0 && length >= 0 && (from >= iterator.itemEnd || from + length <= iterator.itemStart))
|
||||
continue;
|
||||
}
|
||||
|
||||
QPointF pos(iterator.x.toReal(), y);
|
||||
|
||||
QFont font;
|
||||
QGlyphRun::GlyphRunFlags flags;
|
||||
@ -2226,15 +2222,13 @@ QList<QGlyphRun> QTextLine::glyphRuns(int from, int length) const
|
||||
}
|
||||
|
||||
int relativeFrom = qMax(iterator.itemStart, from) - si.position;
|
||||
int relativeTo = qMin(iterator.itemEnd - 1, from + length - 1) - si.position;
|
||||
int relativeTo = qMin(iterator.itemEnd, from + length) - 1 - si.position;
|
||||
|
||||
unsigned short *logClusters = eng->logClusters(&si);
|
||||
int glyphsStart = logClusters[relativeFrom];
|
||||
int glyphsEnd = (relativeTo == eng->length(&si))
|
||||
? si.num_glyphs - 1
|
||||
: logClusters[relativeTo];
|
||||
int glyphsEnd = (relativeTo == iterator.itemLength) ? si.num_glyphs - 1 : logClusters[relativeTo];
|
||||
// the glyph index right next to the requested range
|
||||
int nextGlyphIndex = relativeTo < eng->length(&si) - 1 ? logClusters[relativeTo + 1] : si.num_glyphs;
|
||||
int nextGlyphIndex = (relativeTo < iterator.itemLength - 1) ? logClusters[relativeTo + 1] : si.num_glyphs;
|
||||
if (nextGlyphIndex - 1 > glyphsEnd)
|
||||
glyphsEnd = nextGlyphIndex - 1;
|
||||
bool startsInsideLigature = relativeFrom > 0 && logClusters[relativeFrom - 1] == glyphsStart;
|
||||
|
Loading…
Reference in New Issue
Block a user