From fd0291df92447e46cb980f62c8f45e878c29f6d0 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Fri, 29 Oct 2021 14:08:49 +0300 Subject: [PATCH] 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 --- src/plugins/texteditor/textdocument.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index d9b37a1214e..cee8e3cf314 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -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(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()];