From 4968b0fb230716701149e6820c09fa25a48c5a3e Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Fri, 5 May 2023 15:46:51 +0200 Subject: [PATCH] QTextMarkdownImporter: Fix performance for non-trivial documents While parsing the markdown document, each addition of text and formats was triggering a relayout of the so far existing document, leading to quadratic behavior and very bad performance for any non-trivial markdown document. Guard the changes while parsing with a begin/endEditBlock to avoid these intermediate updates. The performance impact can for example be observed with the markdown editor in Qt Creator (11+). Change-Id: I5f89441ea41bc3c6281b616f0c5528b49b48e432 Reviewed-by: Shawn Rutledge (cherry picked from commit 9f0b4e18cd6929eb161e9526b496f9bb8a6e1c78) Reviewed-by: Qt Cherry-pick Bot --- src/gui/text/qtextmarkdownimporter.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index 8838568fd06..24dbd941e99 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -138,7 +138,9 @@ void QTextMarkdownImporter::import(QTextDocument *doc, const QString &markdown) m_monoFont.setPixelSize(doc->defaultFont().pixelSize()); qCDebug(lcMD) << "default font" << doc->defaultFont() << "mono font" << m_monoFont; QByteArray md = markdown.toUtf8(); + m_cursor->beginEditBlock(); md_parse(md.constData(), MD_SIZE(md.size()), &callbacks, this); + m_cursor->endEditBlock(); delete m_cursor; m_cursor = nullptr; }