From 89e2c330e3bf853e5fc48c5077c36eccd6544a8f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 7 May 2024 15:15:02 +0800 Subject: [PATCH] optimize: don't invalidate all line width after each parsing. --- RedPandaIDE/editor.cpp | 4 ++-- libs/qsynedit/qsynedit/document.cpp | 13 ++++++++++--- libs/qsynedit/qsynedit/document.h | 6 +++--- libs/qsynedit/qsynedit/qsynedit.cpp | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8e6186c5..0f9b4ae2 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2221,7 +2221,7 @@ void Editor::onTooltipTimer() void Editor::onEndParsing() { mIdentCache.clear(); - document()->invalidateAllLineWidth(); + document()->invalidateAllNonTempLineWidth(); invalidate(); } @@ -5505,7 +5505,7 @@ void Editor::applyColorScheme(const QString& schemeName) mCurrentHighlighWordForeground = selectedForeground(); mCurrentHighlighWordBackground = selectedBackground(); } - document()->invalidateAllLineWidth(); + document()->invalidateAllNonTempLineWidth(); invalidate(); } diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index 35284a7a..bee41735 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -1276,12 +1276,20 @@ void Document::invalidateAllLineWidth() thread->start(); } +void Document::invalidateAllNonTempLineWidth() +{ + QMutexLocker locker(&mMutex); + for (PDocumentLine& line:mLines) { + if (!line->mIsTempWidth) + line->mIsTempWidth; + } +} + DocumentLine::DocumentLine(DocumentLine::UpdateWidthFunc updateWidthFunc): mSyntaxState{}, mWidth{-1}, mIsTempWidth{true}, - mUpdateWidthFunc{updateWidthFunc}, - mTimestamp{QDateTime::currentMSecsSinceEpoch()} + mUpdateWidthFunc{updateWidthFunc} { } @@ -1324,7 +1332,6 @@ int DocumentLine::width() void DocumentLine::setLineText(const QString &newLineText) { - mTimestamp = QDateTime::currentMSecsSinceEpoch(); mLineText = newLineText; mGlyphStartCharList = calcGlyphStartCharList(newLineText); invalidateWidth(); diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index f145601e..60691e94 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -179,7 +179,6 @@ private: int mWidth; bool mIsTempWidth; UpdateWidthFunc mUpdateWidthFunc; - qint64 mTimestamp; friend class Document; friend class FindMaxLineWidthThread; }; @@ -349,7 +348,7 @@ public: * @return */ int lineWidth(int line); - + void updateLineWidth(int line); /** @@ -637,7 +636,7 @@ public: void setForceMonospace(bool newForceMonospace); public slots: - void invalidateAllLineWidth(); + void invalidateAllNonTempLineWidth(); signals: void changed(); @@ -659,6 +658,7 @@ protected: emit lineWidthUpdateNeeded(line); } private: + void invalidateAllLineWidth(); bool lineWidthValid(int line); void beginSetLinesWidth(); void endSetLinesWidth(); diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 4a16ac96..48dba0b4 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -4718,7 +4718,7 @@ void QSynEdit::setSyntaxer(const PSyntaxer &syntaxer) reparseDocument(); mDocument->endUpdate(); } - mDocument->invalidateAllLineWidth(); + mDocument->invalidateAllNonTempLineWidth(); invalidate(); }