QString::toHtmlEscaped: avoid unconditional copy
Let's find replaceable chars and then do copy Change-Id: I2d365626218b0daf2023144dee7e901e8e99adc6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>bb10
parent
bd5d313197
commit
0ed8db7800
|
|
@ -9926,10 +9926,14 @@ qsizetype QtPrivate::count(QStringView haystack, const QRegularExpression &re)
|
|||
*/
|
||||
QString QString::toHtmlEscaped() const
|
||||
{
|
||||
const auto pos = std::u16string_view(*this).find_first_of(u"<>&\"");
|
||||
if (pos == std::u16string_view::npos)
|
||||
return *this;
|
||||
QString rich;
|
||||
const qsizetype len = size();
|
||||
rich.reserve(qsizetype(len * 1.1));
|
||||
for (QChar ch : *this) {
|
||||
rich += qToStringViewIgnoringNull(*this).first(pos);
|
||||
for (auto ch : qToStringViewIgnoringNull(*this).sliced(pos)) {
|
||||
if (ch == u'<')
|
||||
rich += "<"_L1;
|
||||
else if (ch == u'>')
|
||||
|
|
|
|||
Loading…
Reference in New Issue