Skip to content

Commit

Permalink
QString: fix premature pessimisation in arg(char-ish)
Browse files Browse the repository at this point in the history
Instead of converting the char or QChar to a QString, convert them to
a QStringView, saving the memory allocation.

Pick-to: 5.15
Change-Id: I023712ec00172f1c8570e762817bfc3a95e01125
Reviewed-by: Lars Knoll <[email protected]>
  • Loading branch information
marc-kdab committed May 13, 2020
1 parent 90f864a commit e201d58
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/corelib/text/qstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8684,9 +8684,7 @@ QString QString::arg(qulonglong a, int fieldWidth, int base, QChar fillChar) con
*/
QString QString::arg(QChar a, int fieldWidth, QChar fillChar) const
{
QString c;
c += a;
return arg(c, fieldWidth, fillChar);
return arg(QStringView{&a, 1}, fieldWidth, fillChar);
}

/*!
Expand All @@ -8696,9 +8694,7 @@ QString QString::arg(QChar a, int fieldWidth, QChar fillChar) const
*/
QString QString::arg(char a, int fieldWidth, QChar fillChar) const
{
QString c;
c += QLatin1Char(a);
return arg(c, fieldWidth, fillChar);
return arg(QLatin1Char(a), fieldWidth, fillChar);
}

/*!
Expand Down

0 comments on commit e201d58

Please sign in to comment.