forked from qt-creator/qt-creator
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:
committed by
BogDan Vatra
parent
a8bc9774f9
commit
fd0291df92
@@ -835,7 +835,7 @@ void TextDocument::cleanWhitespace(const QTextCursor &cursor)
|
|||||||
void TextDocument::cleanWhitespace(QTextCursor &cursor, bool inEntireDocument,
|
void TextDocument::cleanWhitespace(QTextCursor &cursor, bool inEntireDocument,
|
||||||
bool cleanIndentation)
|
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());
|
auto documentLayout = qobject_cast<TextDocumentLayout*>(d->m_document.documentLayout());
|
||||||
Q_ASSERT(cursor.visualNavigation() == false);
|
Q_ASSERT(cursor.visualNavigation() == false);
|
||||||
@@ -862,7 +862,7 @@ void TextDocument::cleanWhitespace(QTextCursor &cursor, bool inEntireDocument,
|
|||||||
foreach (block, blocks) {
|
foreach (block, blocks) {
|
||||||
QString blockText = block.text();
|
QString blockText = block.text();
|
||||||
|
|
||||||
if (d->m_storageSettings.removeTrailingWhitespace(fileName))
|
if (removeTrailingWhitespace)
|
||||||
TabSettings::removeTrailingWhitespace(cursor, block);
|
TabSettings::removeTrailingWhitespace(cursor, block);
|
||||||
|
|
||||||
const int indent = indentations[block.blockNumber()];
|
const int indent = indentations[block.blockNumber()];
|
||||||
|
Reference in New Issue
Block a user