From 6c7738a7d61178cbc809f441bdcd8345c43ba1ca Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 24 May 2024 17:25:01 -0300 Subject: [PATCH] QByteArray: use qulltoString_helper() to make strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/text/qbytearray.cpp | 18 ------------------ src/corelib/text/qlocale_tools.cpp | 12 ++++++++++++ src/corelib/text/qlocale_tools_p.h | 1 + 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index 4c9282df26b..09c103a0b94 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -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 diff --git a/src/corelib/text/qlocale_tools.cpp b/src/corelib/text/qlocale_tools.cpp index b6639bcb711..660216a65c1 100644 --- a/src/corelib/text/qlocale_tools.cpp +++ b/src/corelib/text/qlocale_tools.cpp @@ -552,6 +552,18 @@ QString qulltoa(qulonglong number, int base, const QStringView zero) return QString(reinterpret_cast(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 diff --git a/src/corelib/text/qlocale_tools_p.h b/src/corelib/text/qlocale_tools_p.h index 9b02403ea42..cd012e7afd3 100644 --- a/src/corelib/text/qlocale_tools_p.h +++ b/src/corelib/text/qlocale_tools_p.h @@ -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);