Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.2, 6.8.0 Beta1
-
None
-
Windows 11
Description
The current implementation of QPlainTextEdit's paintEvent method suffers from performance degradation when numerous blocks are marked invisible. This becomes noticeable due to inefficient handling of invisible block skipping, leading to unnecessary computation.
// void QPlainTextEdit::paintEvent(QPaintEvent *e) while (block.isValid()) { QRectF r = blockBoundingRect(block).translated(offset); QTextLayout *layout = block.layout(); if (!block.isVisible()) { offset.ry() += r.height(); block = block.next(); continue; } // .... }
According to blockBoundingRect implementation in the same file and my understanding, when the block is set invisible, the block height should be 0, so offset.ry() += r.height() is useless. Therefore the two lines can be moved below the invisible skipping, avoiding useless blockBoundingRect call.
QRectF QPlainTextDocumentLayout::blockBoundingRect(const QTextBlock &block) const { if (!block.isValid()) { return QRectF(); } QTextLayout *tl = block.layout(); if (!tl->lineCount()) const_cast<QPlainTextDocumentLayout*>(this)->layoutBlock(block); QRectF br; if (block.isVisible()) { br = QRectF(QPointF(0, 0), tl->boundingRect().bottomRight()); if (tl->lineCount() == 1) br.setWidth(qMax(br.width(), tl->lineAt(0).naturalTextWidth())); qreal margin = document()->documentMargin(); br.adjust(0, 0, margin, 0); if (!block.next().isValid()) br.adjust(0, 0, 0, margin); } return br; }