diff options
author | Tobias Hunger <tobias.hunger@digia.com> | 2014-01-17 16:04:14 +0100 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@digia.com> | 2014-01-20 11:15:19 +0100 |
commit | 671d2d729e57882bc35037556ef1496326fdbd2c (patch) | |
tree | d0dcc8143572f6fceacd42462e60493c9a4fc085 /src/libs/utils/ansiescapecodehandler.cpp | |
parent | 7168dd48fe3aed7896a699b0375a9ccdbdb06029 (diff) |
AnsiEscapeHandler: Avoid some iterations over the string
Find the first escape sequence by iterating over the string once
and reuse that value during the complete initialization.
Change-Id: I6a4dd3bb4da97923410a99dbb03210ffdc6ae27f
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Diffstat (limited to 'src/libs/utils/ansiescapecodehandler.cpp')
-rw-r--r-- | src/libs/utils/ansiescapecodehandler.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/libs/utils/ansiescapecodehandler.cpp b/src/libs/utils/ansiescapecodehandler.cpp index cbd5ccee05..190093767f 100644 --- a/src/libs/utils/ansiescapecodehandler.cpp +++ b/src/libs/utils/ansiescapecodehandler.cpp @@ -90,17 +90,18 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input QTextCharFormat charFormat = m_previousFormatClosed ? input.format : m_previousFormat; const QString escape = QLatin1String("\x1b["); - if (!input.text.contains(escape)) { + const int escapePos = input.text.indexOf(escape); + if (escapePos < 0) { outputData << FormattedText(input.text, charFormat); return outputData; - } else if (!input.text.startsWith(escape)) { - outputData << FormattedText(input.text.left(input.text.indexOf(escape)), charFormat); + } else if (escapePos != 0) { + outputData << FormattedText(input.text.left(escapePos), charFormat); } const QChar semicolon = QLatin1Char(';'); const QChar colorTerminator = QLatin1Char('m'); // strippedText always starts with "\e[" - QString strippedText = input.text.mid(input.text.indexOf(escape)); + QString strippedText = input.text.mid(escapePos); while (!strippedText.isEmpty()) { while (strippedText.startsWith(escape)) { strippedText.remove(0, 2); |