From c7cb95d18b6802a6e62bc6b44260bbf3d90bc7ab Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 29 Nov 2017 21:45:06 +0800 Subject: [PATCH] Markdown Highlighter: speed up at first parse --- src/hgmarkdownhighlighter.cpp | 19 +++++++++++++++---- src/hgmarkdownhighlighter.h | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/hgmarkdownhighlighter.cpp b/src/hgmarkdownhighlighter.cpp index a4e8d497..a0266e64 100644 --- a/src/hgmarkdownhighlighter.cpp +++ b/src/hgmarkdownhighlighter.cpp @@ -29,9 +29,16 @@ HGMarkdownHighlighter::HGMarkdownHighlighter(const QVector &s const QHash &codeBlockStyles, int waitInterval, QTextDocument *parent) - : QSyntaxHighlighter(parent), highlightingStyles(styles), - m_codeBlockStyles(codeBlockStyles), m_numOfCodeBlockHighlightsToRecv(0), - parsing(0), waitInterval(waitInterval), content(NULL), capacity(0), result(NULL) + : QSyntaxHighlighter(parent), + highlightingStyles(styles), + m_codeBlockStyles(codeBlockStyles), + m_numOfCodeBlockHighlightsToRecv(0), + parsing(0), + waitInterval(waitInterval), + m_firstParse(true), + content(NULL), + capacity(0), + result(NULL) { codeBlockStartExp = QRegExp(VUtils::c_fencedCodeBlockStartRegExp); codeBlockEndExp = QRegExp(VUtils::c_fencedCodeBlockEndRegExp); @@ -541,11 +548,15 @@ void HGMarkdownHighlighter::timerTimeout() { qDebug() << "HGMarkdownHighlighter start a new parse"; parse(); - if (!updateCodeBlocks()) { + if (!updateCodeBlocks() || m_firstParse) { rehighlight(); } highlightChanged(); + + if (m_firstParse) { + m_firstParse = false; + } } void HGMarkdownHighlighter::updateHighlight() diff --git a/src/hgmarkdownhighlighter.h b/src/hgmarkdownhighlighter.h index f51132f8..e8a83402 100644 --- a/src/hgmarkdownhighlighter.h +++ b/src/hgmarkdownhighlighter.h @@ -190,6 +190,9 @@ private: QTimer *timer; int waitInterval; + // Whether this is the first parse. + bool m_firstParse; + char *content; int capacity; pmh_element **result;