diff --git a/src/decoders/PlainTextDecoder.cpp b/src/decoders/PlainTextDecoder.cpp index 9fcfc027..1c5a6dc0 100644 --- a/src/decoders/PlainTextDecoder.cpp +++ b/src/decoders/PlainTextDecoder.cpp @@ -69,12 +69,6 @@ void PlainTextDecoder::decodeLine(const Character *const characters, int count, // TODO should we ignore or respect the LINE_WRAPPED line property? - // note: we build up a QString and send it to the text stream rather writing into the text - // stream a character at a time because it is more efficient. - //(since QTextStream always deals with QStrings internally anyway) - QString plainText; - plainText.reserve(count); - // If we should remove leading whitespace find the first non-space character int start = 0; if (!_includeLeadingWhitespace) { @@ -109,14 +103,19 @@ void PlainTextDecoder::decodeLine(const Character *const characters, int count, } } + // note: we build up a QVector and send it to the text stream transformed into a QString + // rather than writing into the text stream a character at a time because it is more efficient. + //(since QTextStream always deals with QStrings internally anyway) + QVector characterBuffer; + characterBuffer.reserve(count); + for (int i = start; i < outputCount;) { if ((characters[i].rendition & RE_EXTENDED_CHAR) != 0) { ushort extendedCharLength = 0; const uint *chars = ExtendedCharTable::instance.lookupExtendedChar(characters[i].character, extendedCharLength); if (chars != nullptr) { - const QString s = QString::fromUcs4(chars, extendedCharLength); - plainText.append(s); - i += qMax(1, Character::stringWidth(s)); + characterBuffer.insert(characterBuffer.end(), extendedCharLength, *chars); + i += qMax(1, Character::stringWidth(chars, extendedCharLength)); } else { ++i; } @@ -129,12 +128,12 @@ void PlainTextDecoder::decodeLine(const Character *const characters, int count, // lost in some situation. One typical example is copying the result // of `dialog --infobox "qwe" 10 10` . if (characters[i].isRealCharacter || i <= realCharacterGuard) { - plainText.append(QString::fromUcs4(&characters[i].character, 1)); + characterBuffer.append(characters[i].character); i += qMax(1, characters[i].width()); } else { ++i; // should we 'break' directly here? } } } - *_output << plainText; + *_output << QString::fromUcs4(characterBuffer.data(), characterBuffer.size()); }