QByteArray: use qulltoString_helper() to make strings
Mårten made this code ready for QByteArray in commits e5e8e4f59ba4c3d59303220a57677360992eb553 and 5d0542a356be1c47e2f99e6ba38b8e520ca0710c, but never actually made QByteArray use it. The simplest change of moving qulltoa2() is sufficient, instead of moving the template to the header and using it in qbytearray.cpp. qulltoa2() is called in three places and we don't want the compiler to inline the function there, so having the function in a separate TU accomplishes that for us. GCC won't inline it in LTO builds either. Change-Id: If3345151ddf84c43a4f1fffd17d28682445fbdaa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
297cdf16d0
commit
6c7738a7d6
@ -4190,24 +4190,6 @@ QByteArray QByteArray::toBase64(Base64Options options) const
|
||||
\sa toUShort()
|
||||
*/
|
||||
|
||||
static char *qulltoa2(char *p, qulonglong n, int base)
|
||||
{
|
||||
#if defined(QT_CHECK_RANGE)
|
||||
if (base < 2 || base > 36) {
|
||||
qWarning("QByteArray::setNum: Invalid base %d", base);
|
||||
base = 10;
|
||||
}
|
||||
#endif
|
||||
constexpr char b = 'a' - 10;
|
||||
do {
|
||||
const int c = n % base;
|
||||
n /= base;
|
||||
*--p = c + (c < 10 ? '0' : b);
|
||||
} while (n);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
|
@ -552,6 +552,18 @@ QString qulltoa(qulonglong number, int base, const QStringView zero)
|
||||
return QString(reinterpret_cast<QChar *>(p), end - p);
|
||||
}
|
||||
|
||||
char *qulltoa2(char *p, qulonglong n, int base)
|
||||
{
|
||||
#if defined(QT_CHECK_RANGE)
|
||||
if (base < 2 || base > 36) {
|
||||
qWarning("QByteArray::setNum: Invalid base %d", base);
|
||||
base = 10;
|
||||
}
|
||||
#endif
|
||||
qulltoString_helper(n, base, p);
|
||||
return p;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
|
||||
|
@ -36,6 +36,7 @@ void qt_doubleToAscii(double d, QLocaleData::DoubleForm form, int precision,
|
||||
|
||||
[[nodiscard]] QString qulltoBasicLatin(qulonglong l, int base, bool negative);
|
||||
[[nodiscard]] QString qulltoa(qulonglong l, int base, const QStringView zero);
|
||||
[[nodiscard]] char *qulltoa2(char *p, qulonglong n, int base);
|
||||
[[nodiscard]] Q_CORE_EXPORT QString qdtoa(qreal d, int *decpt, int *sign);
|
||||
[[nodiscard]] QString qdtoBasicLatin(double d, QLocaleData::DoubleForm form,
|
||||
int precision, bool uppercase);
|
||||
|
Loading…
x
Reference in New Issue
Block a user