From 5df601d9ee101794ded1f01818b219d0509cfafd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Javier=20Merino=20Mor=C3=A1n?= Date: Sun, 5 Dec 2021 17:56:52 +0100 Subject: [PATCH] Avoid moving memory around in copyLineToStream If the "Trim leading spaces" option is set, we can pass a pointer to the first non-space character to decodeLine(), no need to first move memory around. --- src/Screen.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Screen.cpp b/src/Screen.cpp index 044b90ef..b223ed2c 100644 --- a/src/Screen.cpp +++ b/src/Screen.cpp @@ -1634,8 +1634,8 @@ int Screen::copyLineToStream(int line, } } + int spacesCount = 0; if ((options & TrimLeadingWhitespace) != 0U) { - int spacesCount = 0; for (spacesCount = 0; spacesCount < count; ++spacesCount) { if (QChar::category(characterBuffer[spacesCount].character) != QChar::Category::Separator_Space) { break; @@ -1646,13 +1646,11 @@ int Screen::copyLineToStream(int line, return 0; } - std::copy(characterBuffer + spacesCount, characterBuffer + count, characterBuffer); - count -= spacesCount; } // decode line and write to text stream - decoder->decodeLine(characterBuffer, count, currentLineProperties); + decoder->decodeLine(characterBuffer + spacesCount, count, currentLineProperties); return count; }