Make TextDocument::cleanWhitespace super fast

On documents with a lot of lines of code (e.g. ~30k) saving the
documents takes ages (+6 seconds).
With this change the time is reduced to less than 150ms.

Change-Id: I8a40253a91ae40a6681d5acf1f09711c9b63bd6f
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
BogDan Vatra
2021-10-29 14:08:49 +03:00
committed by BogDan Vatra
parent a8bc9774f9
commit fd0291df92

View File

@@ -835,7 +835,7 @@ void TextDocument::cleanWhitespace(const QTextCursor &cursor)
void TextDocument::cleanWhitespace(QTextCursor &cursor, bool inEntireDocument,
bool cleanIndentation)
{
const QString fileName(filePath().fileName());
const bool removeTrailingWhitespace = d->m_storageSettings.removeTrailingWhitespace(filePath().fileName());
auto documentLayout = qobject_cast<TextDocumentLayout*>(d->m_document.documentLayout());
Q_ASSERT(cursor.visualNavigation() == false);
@@ -862,7 +862,7 @@ void TextDocument::cleanWhitespace(QTextCursor &cursor, bool inEntireDocument,
foreach (block, blocks) {
QString blockText = block.text();
if (d->m_storageSettings.removeTrailingWhitespace(fileName))
if (removeTrailingWhitespace)
TabSettings::removeTrailingWhitespace(cursor, block);
const int indent = indentations[block.blockNumber()];