Skip to content

Commit 97cdee8

Browse files
authored
Merge pull request #27 from cpeditor/fix-performance
perf: fix the performance issue of the line number area
2 parents baf096a + 4b981c4 commit 97cdee8

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/internal/QLineNumberArea.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,14 @@ QSize QLineNumberArea::sizeHint() const
2323
return QWidget::sizeHint();
2424
}
2525

26-
int space = 0;
27-
int lineCount = m_codeEditParent->document()->blockCount();
26+
const int digits = QString::number(m_codeEditParent->document()->blockCount()).length();
27+
int space;
2828

29-
for (int i = 0; i <= lineCount; ++i)
30-
{
3129
#if QT_VERSION >= 0x050B00
32-
space = 15 + m_codeEditParent->fontMetrics().horizontalAdvance(QString::number(i));
30+
space = 15 + m_codeEditParent->fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
3331
#else
34-
space = 15 + m_codeEditParent->fontMetrics().width(QLatin1Char(QString::number(i)));
32+
space = 15 + m_codeEditParent->fontMetrics().width(QLatin1Char('9')) * digits;
3533
#endif
36-
}
3734

3835
return {space, 0};
3936
}

0 commit comments

Comments
 (0)