forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user