optimize: don't invalidate all line width after each parsing.

This commit is contained in:
Roy Qu 2024-05-07 15:15:02 +08:00
parent 8fef396baa
commit 89e2c330e3
4 changed files with 16 additions and 9 deletions

View File

@ -2221,7 +2221,7 @@ void Editor::onTooltipTimer()
void Editor::onEndParsing() void Editor::onEndParsing()
{ {
mIdentCache.clear(); mIdentCache.clear();
document()->invalidateAllLineWidth(); document()->invalidateAllNonTempLineWidth();
invalidate(); invalidate();
} }
@ -5505,7 +5505,7 @@ void Editor::applyColorScheme(const QString& schemeName)
mCurrentHighlighWordForeground = selectedForeground(); mCurrentHighlighWordForeground = selectedForeground();
mCurrentHighlighWordBackground = selectedBackground(); mCurrentHighlighWordBackground = selectedBackground();
} }
document()->invalidateAllLineWidth(); document()->invalidateAllNonTempLineWidth();
invalidate(); invalidate();
} }

View File

@ -1276,12 +1276,20 @@ void Document::invalidateAllLineWidth()
thread->start(); thread->start();
} }
void Document::invalidateAllNonTempLineWidth()
{
QMutexLocker locker(&mMutex);
for (PDocumentLine& line:mLines) {
if (!line->mIsTempWidth)
line->mIsTempWidth;
}
}
DocumentLine::DocumentLine(DocumentLine::UpdateWidthFunc updateWidthFunc): DocumentLine::DocumentLine(DocumentLine::UpdateWidthFunc updateWidthFunc):
mSyntaxState{}, mSyntaxState{},
mWidth{-1}, mWidth{-1},
mIsTempWidth{true}, mIsTempWidth{true},
mUpdateWidthFunc{updateWidthFunc}, mUpdateWidthFunc{updateWidthFunc}
mTimestamp{QDateTime::currentMSecsSinceEpoch()}
{ {
} }
@ -1324,7 +1332,6 @@ int DocumentLine::width()
void DocumentLine::setLineText(const QString &newLineText) void DocumentLine::setLineText(const QString &newLineText)
{ {
mTimestamp = QDateTime::currentMSecsSinceEpoch();
mLineText = newLineText; mLineText = newLineText;
mGlyphStartCharList = calcGlyphStartCharList(newLineText); mGlyphStartCharList = calcGlyphStartCharList(newLineText);
invalidateWidth(); invalidateWidth();

View File

@ -179,7 +179,6 @@ private:
int mWidth; int mWidth;
bool mIsTempWidth; bool mIsTempWidth;
UpdateWidthFunc mUpdateWidthFunc; UpdateWidthFunc mUpdateWidthFunc;
qint64 mTimestamp;
friend class Document; friend class Document;
friend class FindMaxLineWidthThread; friend class FindMaxLineWidthThread;
}; };
@ -637,7 +636,7 @@ public:
void setForceMonospace(bool newForceMonospace); void setForceMonospace(bool newForceMonospace);
public slots: public slots:
void invalidateAllLineWidth(); void invalidateAllNonTempLineWidth();
signals: signals:
void changed(); void changed();
@ -659,6 +658,7 @@ protected:
emit lineWidthUpdateNeeded(line); emit lineWidthUpdateNeeded(line);
} }
private: private:
void invalidateAllLineWidth();
bool lineWidthValid(int line); bool lineWidthValid(int line);
void beginSetLinesWidth(); void beginSetLinesWidth();
void endSetLinesWidth(); void endSetLinesWidth();

View File

@ -4718,7 +4718,7 @@ void QSynEdit::setSyntaxer(const PSyntaxer &syntaxer)
reparseDocument(); reparseDocument();
mDocument->endUpdate(); mDocument->endUpdate();
} }
mDocument->invalidateAllLineWidth(); mDocument->invalidateAllNonTempLineWidth();
invalidate(); invalidate();
} }