QByteArray/QString: don't unnecessarily use QArrayDataPointer::operator->
The operator->() function casts *this to QArrayDataOps, a type that *this technically isn't. This has been harmless since forever, but is technically UB, and does prevent using these functions in a constexpr context (something we can't do yet, but will in 6.9). Change-Id: I398f9e3d83d44f198a69fffd17e26fc8cd9a572f (cherry picked from commit ffbb585f6fa5e97aee81387f275342b049ba7d9c) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
fe200fb713
commit
7a250d9d67
@ -492,7 +492,7 @@ public:
|
|||||||
static QByteArray fromStdString(const std::string &s);
|
static QByteArray fromStdString(const std::string &s);
|
||||||
std::string toStdString() const;
|
std::string toStdString() const;
|
||||||
|
|
||||||
inline qsizetype size() const noexcept { return d->size; }
|
inline qsizetype size() const noexcept { return d.size; }
|
||||||
#if QT_DEPRECATED_SINCE(6, 4)
|
#if QT_DEPRECATED_SINCE(6, 4)
|
||||||
QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
|
QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
|
||||||
inline qsizetype count() const noexcept { return size(); }
|
inline qsizetype count() const noexcept { return size(); }
|
||||||
@ -624,30 +624,30 @@ inline const char *QByteArray::data() const noexcept
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
inline void QByteArray::detach()
|
inline void QByteArray::detach()
|
||||||
{ if (d->needsDetach()) reallocData(size(), QArrayData::KeepSize); }
|
{ if (d.needsDetach()) reallocData(size(), QArrayData::KeepSize); }
|
||||||
inline bool QByteArray::isDetached() const
|
inline bool QByteArray::isDetached() const
|
||||||
{ return !d->isShared(); }
|
{ return !d.isShared(); }
|
||||||
inline QByteArray::QByteArray(const QByteArray &a) noexcept : d(a.d)
|
inline QByteArray::QByteArray(const QByteArray &a) noexcept : d(a.d)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline qsizetype QByteArray::capacity() const { return qsizetype(d->constAllocatedCapacity()); }
|
inline qsizetype QByteArray::capacity() const { return qsizetype(d.constAllocatedCapacity()); }
|
||||||
|
|
||||||
inline void QByteArray::reserve(qsizetype asize)
|
inline void QByteArray::reserve(qsizetype asize)
|
||||||
{
|
{
|
||||||
if (d->needsDetach() || asize > capacity() - d->freeSpaceAtBegin())
|
if (d.needsDetach() || asize > capacity() - d.freeSpaceAtBegin())
|
||||||
reallocData(qMax(size(), asize), QArrayData::KeepSize);
|
reallocData(qMax(size(), asize), QArrayData::KeepSize);
|
||||||
if (d->constAllocatedCapacity())
|
if (d.constAllocatedCapacity())
|
||||||
d->setFlag(Data::CapacityReserved);
|
d.setFlag(Data::CapacityReserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void QByteArray::squeeze()
|
inline void QByteArray::squeeze()
|
||||||
{
|
{
|
||||||
if (!d.isMutable())
|
if (!d.isMutable())
|
||||||
return;
|
return;
|
||||||
if (d->needsDetach() || size() < capacity())
|
if (d.needsDetach() || size() < capacity())
|
||||||
reallocData(size(), QArrayData::KeepSize);
|
reallocData(size(), QArrayData::KeepSize);
|
||||||
if (d->constAllocatedCapacity())
|
if (d.constAllocatedCapacity())
|
||||||
d->clearFlag(Data::CapacityReserved);
|
d.clearFlag(Data::CapacityReserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline char &QByteArray::operator[](qsizetype i)
|
inline char &QByteArray::operator[](qsizetype i)
|
||||||
@ -704,7 +704,7 @@ inline QByteArray &QByteArray::setNum(float n, char format, int precision)
|
|||||||
#if QT_CORE_INLINE_IMPL_SINCE(6, 4)
|
#if QT_CORE_INLINE_IMPL_SINCE(6, 4)
|
||||||
bool QByteArray::isNull() const noexcept
|
bool QByteArray::isNull() const noexcept
|
||||||
{
|
{
|
||||||
return d->isNull();
|
return d.isNull();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if QT_CORE_INLINE_IMPL_SINCE(6, 8)
|
#if QT_CORE_INLINE_IMPL_SINCE(6, 8)
|
||||||
|
@ -993,7 +993,7 @@ public:
|
|||||||
emscripten::val toEcmaString() const;
|
emscripten::val toEcmaString() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
inline bool isNull() const { return d->isNull(); }
|
inline bool isNull() const { return d.isNull(); }
|
||||||
|
|
||||||
bool isRightToLeft() const;
|
bool isRightToLeft() const;
|
||||||
[[nodiscard]] bool isValidUtf16() const noexcept
|
[[nodiscard]] bool isValidUtf16() const noexcept
|
||||||
@ -1248,14 +1248,14 @@ QChar *QString::data()
|
|||||||
const QChar *QString::constData() const
|
const QChar *QString::constData() const
|
||||||
{ return data(); }
|
{ return data(); }
|
||||||
void QString::detach()
|
void QString::detach()
|
||||||
{ if (d->needsDetach()) reallocData(d.size, QArrayData::KeepSize); }
|
{ if (d.needsDetach()) reallocData(d.size, QArrayData::KeepSize); }
|
||||||
bool QString::isDetached() const
|
bool QString::isDetached() const
|
||||||
{ return !d->isShared(); }
|
{ return !d.isShared(); }
|
||||||
void QString::clear()
|
void QString::clear()
|
||||||
{ if (!isNull()) *this = QString(); }
|
{ if (!isNull()) *this = QString(); }
|
||||||
QString::QString(const QString &other) noexcept : d(other.d)
|
QString::QString(const QString &other) noexcept : d(other.d)
|
||||||
{ }
|
{ }
|
||||||
qsizetype QString::capacity() const { return qsizetype(d->constAllocatedCapacity()); }
|
qsizetype QString::capacity() const { return qsizetype(d.constAllocatedCapacity()); }
|
||||||
QString &QString::setNum(short n, int base)
|
QString &QString::setNum(short n, int base)
|
||||||
{ return setNum(qlonglong(n), base); }
|
{ return setNum(qlonglong(n), base); }
|
||||||
QString &QString::setNum(ushort n, int base)
|
QString &QString::setNum(ushort n, int base)
|
||||||
@ -1326,20 +1326,20 @@ QString::~QString() {}
|
|||||||
|
|
||||||
void QString::reserve(qsizetype asize)
|
void QString::reserve(qsizetype asize)
|
||||||
{
|
{
|
||||||
if (d->needsDetach() || asize >= capacity() - d.freeSpaceAtBegin())
|
if (d.needsDetach() || asize >= capacity() - d.freeSpaceAtBegin())
|
||||||
reallocData(qMax(asize, size()), QArrayData::KeepSize);
|
reallocData(qMax(asize, size()), QArrayData::KeepSize);
|
||||||
if (d->constAllocatedCapacity())
|
if (d.constAllocatedCapacity())
|
||||||
d->setFlag(Data::CapacityReserved);
|
d.setFlag(Data::CapacityReserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QString::squeeze()
|
void QString::squeeze()
|
||||||
{
|
{
|
||||||
if (!d.isMutable())
|
if (!d.isMutable())
|
||||||
return;
|
return;
|
||||||
if (d->needsDetach() || size() < capacity())
|
if (d.needsDetach() || size() < capacity())
|
||||||
reallocData(d.size, QArrayData::KeepSize);
|
reallocData(d.size, QArrayData::KeepSize);
|
||||||
if (d->constAllocatedCapacity())
|
if (d.constAllocatedCapacity())
|
||||||
d->clearFlag(Data::CapacityReserved);
|
d.clearFlag(Data::CapacityReserved);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString &QString::setUtf16(const ushort *autf16, qsizetype asize)
|
QString &QString::setUtf16(const ushort *autf16, qsizetype asize)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user