Make QString::fromRawData() inline

And make it and the QByteArray equivalent use the QArrayDataPointer
function of the same name, which hides the const_cast.

Change-Id: I15d7b43afb6269eba411fffd496bca3f13e86a8e
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2024-08-27 10:36:55 -07:00 committed by Marc Mutz
parent 4b278fd998
commit cf2f102684
4 changed files with 10 additions and 6 deletions

View File

@ -1427,6 +1427,7 @@ QNoDebug QMessageLogger::noDebug() const noexcept
return QNoDebug(); return QNoDebug();
} }
#include "qstring.h" // inlined API
// #include "qotherheader.h" // #include "qotherheader.h"
// // implement removed functions from qotherheader.h // // implement removed functions from qotherheader.h

View File

@ -408,7 +408,7 @@ public:
[[nodiscard]] static QByteArray number(double, char format = 'g', int precision = 6); [[nodiscard]] static QByteArray number(double, char format = 'g', int precision = 6);
[[nodiscard]] static QByteArray fromRawData(const char *data, qsizetype size) [[nodiscard]] static QByteArray fromRawData(const char *data, qsizetype size)
{ {
return QByteArray(DataPointer(nullptr, const_cast<char *>(data), size)); return QByteArray(DataPointer::fromRawData(data, size));
} }
class FromBase64Result; class FromBase64Result;

View File

@ -9411,10 +9411,6 @@ QString::iterator QString::erase(QString::const_iterator first, QString::const_i
\fn QString QString::fromRawData(const QChar *unicode, qsizetype size) \fn QString QString::fromRawData(const QChar *unicode, qsizetype size)
\overload \overload
*/ */
QString QString::fromRawData(const QChar *unicode, qsizetype size)
{
return QString(DataPointer::fromRawData(const_cast<char16_t *>(reinterpret_cast<const char16_t *>(unicode)), size));
}
/*! /*!
\since 4.7 \since 4.7

View File

@ -784,8 +784,9 @@ public:
static QString fromUcs4(const char32_t *, qsizetype size = -1); static QString fromUcs4(const char32_t *, qsizetype size = -1);
static QString fromRawData(const char16_t *unicode, qsizetype size) static QString fromRawData(const char16_t *unicode, qsizetype size)
{ {
return QString(DataPointer(nullptr, const_cast<char16_t *>(unicode), size)); return QString(DataPointer::fromRawData(unicode, size));
} }
QT_CORE_INLINE_SINCE(6, 10)
static QString fromRawData(const QChar *, qsizetype size); static QString fromRawData(const QChar *, qsizetype size);
#if QT_DEPRECATED_SINCE(6, 0) #if QT_DEPRECATED_SINCE(6, 0)
@ -1651,6 +1652,12 @@ qsizetype QString::lastIndexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs)
return qToStringViewIgnoringNull(*this).lastIndexOf(ch, from, cs); return qToStringViewIgnoringNull(*this).lastIndexOf(ch, from, cs);
} }
#endif #endif
#if QT_CORE_INLINE_IMPL_SINCE(6, 10)
QString QString::fromRawData(const QChar *unicode, qsizetype size)
{
return fromRawData(reinterpret_cast<const char16_t *>(unicode), size);
}
#endif
namespace QtPrivate { namespace QtPrivate {
// used by qPrintable() and qUtf8Printable() macros // used by qPrintable() and qUtf8Printable() macros