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()
{
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();
}

View File

@ -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();

View File

@ -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();

View File

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