Optimize QTextEngine::findItem() usage cases
Since the item positions are guaranteed to grow, we could safely re-use the obtained first item while looking for the last item in the chain. Change-Id: I5e42f5de820c62a51a109a4b227b031c697aa898 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
This commit is contained in:
parent
073a16e50e
commit
fa00afe7d7
@ -918,10 +918,11 @@ void QTextEngine::shapeLine(const QScriptLine &line)
|
||||
{
|
||||
QFixed x;
|
||||
bool first = true;
|
||||
const int end = findItem(line.from + line.length - 1);
|
||||
int item = findItem(line.from);
|
||||
if (item == -1)
|
||||
return;
|
||||
|
||||
const int end = findItem(line.from + line.length - 1, item);
|
||||
for ( ; item <= end; ++item) {
|
||||
QScriptItem &si = layoutData->items[item];
|
||||
if (si.analysis.flags == QScriptAnalysis::Tab) {
|
||||
@ -1747,13 +1748,13 @@ bool QTextEngine::isRightToLeft() const
|
||||
}
|
||||
|
||||
|
||||
int QTextEngine::findItem(int strPos) const
|
||||
int QTextEngine::findItem(int strPos, int firstItem) const
|
||||
{
|
||||
itemize();
|
||||
if (strPos < 0 || strPos >= layoutData->string.size())
|
||||
if (strPos < 0 || strPos >= layoutData->string.size() || firstItem < 0)
|
||||
return -1;
|
||||
|
||||
int left = 1;
|
||||
int left = firstItem + 1;
|
||||
int right = layoutData->items.size()-1;
|
||||
while(left <= right) {
|
||||
int middle = ((right-left)/2)+left;
|
||||
@ -2172,7 +2173,7 @@ void QTextEngine::justify(const QScriptLine &line)
|
||||
return;
|
||||
|
||||
int firstItem = findItem(line.from);
|
||||
int lastItem = findItem(line.from + line_length - 1);
|
||||
int lastItem = findItem(line.from + line_length - 1, firstItem);
|
||||
int nItems = (firstItem >= 0 && lastItem >= firstItem)? (lastItem-firstItem+1) : 0;
|
||||
|
||||
QVarLengthArray<QJustificationPoint> justificationPoints;
|
||||
@ -3529,7 +3530,7 @@ QTextLineItemIterator::QTextLineItemIterator(QTextEngine *_eng, int _lineNum, co
|
||||
lineNum(_lineNum),
|
||||
lineEnd(line.from + line.length),
|
||||
firstItem(eng->findItem(line.from)),
|
||||
lastItem(eng->findItem(lineEnd - 1)),
|
||||
lastItem(eng->findItem(lineEnd - 1, firstItem)),
|
||||
nItems((firstItem >= 0 && lastItem >= firstItem)? (lastItem-firstItem+1) : 0),
|
||||
logicalItem(-1),
|
||||
item(-1),
|
||||
|
@ -512,7 +512,7 @@ public:
|
||||
|
||||
void freeMemory();
|
||||
|
||||
int findItem(int strPos) const;
|
||||
int findItem(int strPos, int firstItem = 0) const;
|
||||
inline QTextFormatCollection *formatCollection() const {
|
||||
if (block.docHandle())
|
||||
return block.docHandle()->formatCollection();
|
||||
|
@ -2685,7 +2685,7 @@ qreal QTextLine::cursorToX(int *cursorPos, Edge edge) const
|
||||
// add the items left of the cursor
|
||||
|
||||
int firstItem = eng->findItem(line.from);
|
||||
int lastItem = eng->findItem(lineEnd - 1);
|
||||
int lastItem = eng->findItem(lineEnd - 1, itm);
|
||||
int nItems = (firstItem >= 0 && lastItem >= firstItem)? (lastItem-firstItem+1) : 0;
|
||||
|
||||
QVarLengthArray<int> visualOrder(nItems);
|
||||
@ -2786,7 +2786,7 @@ int QTextLine::xToCursor(qreal _x, CursorPosition cpos) const
|
||||
return line.from;
|
||||
|
||||
int firstItem = eng->findItem(line.from);
|
||||
int lastItem = eng->findItem(line.from + line_length - 1);
|
||||
int lastItem = eng->findItem(line.from + line_length - 1, firstItem);
|
||||
int nItems = (firstItem >= 0 && lastItem >= firstItem)? (lastItem-firstItem+1) : 0;
|
||||
|
||||
if (!nItems)
|
||||
|
Loading…
Reference in New Issue
Block a user