Commit 671d2d72 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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: default avatarDaniel Teske <daniel.teske@digia.com>
parent 7168dd48
...@@ -90,17 +90,18 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input ...@@ -90,17 +90,18 @@ QList<FormattedText> AnsiEscapeCodeHandler::parseText(const FormattedText &input
QTextCharFormat charFormat = m_previousFormatClosed ? input.format : m_previousFormat; QTextCharFormat charFormat = m_previousFormatClosed ? input.format : m_previousFormat;
const QString escape = QLatin1String("\x1b["); 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); outputData << FormattedText(input.text, charFormat);
return outputData; return outputData;
} else if (!input.text.startsWith(escape)) { } else if (escapePos != 0) {
outputData << FormattedText(input.text.left(input.text.indexOf(escape)), charFormat); outputData << FormattedText(input.text.left(escapePos), charFormat);
} }
const QChar semicolon = QLatin1Char(';'); const QChar semicolon = QLatin1Char(';');
const QChar colorTerminator = QLatin1Char('m'); const QChar colorTerminator = QLatin1Char('m');
// strippedText always starts with "\e[" // 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.isEmpty()) {
while (strippedText.startsWith(escape)) { while (strippedText.startsWith(escape)) {
strippedText.remove(0, 2); strippedText.remove(0, 2);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment