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);
|
||||
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)
|
||||
QT_DEPRECATED_VERSION_X_6_4("Use size() or length() instead.")
|
||||
inline qsizetype count() const noexcept { return size(); }
|
||||
@ -624,30 +624,30 @@ inline const char *QByteArray::data() const noexcept
|
||||
#endif
|
||||
}
|
||||
inline void QByteArray::detach()
|
||||
{ if (d->needsDetach()) reallocData(size(), QArrayData::KeepSize); }
|
||||
{ if (d.needsDetach()) reallocData(size(), QArrayData::KeepSize); }
|
||||
inline bool QByteArray::isDetached() const
|
||||
{ return !d->isShared(); }
|
||||
{ return !d.isShared(); }
|
||||
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)
|
||||
{
|
||||
if (d->needsDetach() || asize > capacity() - d->freeSpaceAtBegin())
|
||||
if (d.needsDetach() || asize > capacity() - d.freeSpaceAtBegin())
|
||||
reallocData(qMax(size(), asize), QArrayData::KeepSize);
|
||||
if (d->constAllocatedCapacity())
|
||||
d->setFlag(Data::CapacityReserved);
|
||||
if (d.constAllocatedCapacity())
|
||||
d.setFlag(Data::CapacityReserved);
|
||||
}
|
||||
|
||||
inline void QByteArray::squeeze()
|
||||
{
|
||||
if (!d.isMutable())
|
||||
return;
|
||||
if (d->needsDetach() || size() < capacity())
|
||||
if (d.needsDetach() || size() < capacity())
|
||||
reallocData(size(), QArrayData::KeepSize);
|
||||
if (d->constAllocatedCapacity())
|
||||
d->clearFlag(Data::CapacityReserved);
|
||||
if (d.constAllocatedCapacity())
|
||||
d.clearFlag(Data::CapacityReserved);
|
||||
}
|
||||
|
||||
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)
|
||||
bool QByteArray::isNull() const noexcept
|
||||
{
|
||||
return d->isNull();
|
||||
return d.isNull();
|
||||
}
|
||||
#endif
|
||||
#if QT_CORE_INLINE_IMPL_SINCE(6, 8)
|
||||
|
@ -993,7 +993,7 @@ public:
|
||||
emscripten::val toEcmaString() const;
|
||||
#endif
|
||||
|
||||
inline bool isNull() const { return d->isNull(); }
|
||||
inline bool isNull() const { return d.isNull(); }
|
||||
|
||||
bool isRightToLeft() const;
|
||||
[[nodiscard]] bool isValidUtf16() const noexcept
|
||||
@ -1248,14 +1248,14 @@ QChar *QString::data()
|
||||
const QChar *QString::constData() const
|
||||
{ return data(); }
|
||||
void QString::detach()
|
||||
{ if (d->needsDetach()) reallocData(d.size, QArrayData::KeepSize); }
|
||||
{ if (d.needsDetach()) reallocData(d.size, QArrayData::KeepSize); }
|
||||
bool QString::isDetached() const
|
||||
{ return !d->isShared(); }
|
||||
{ return !d.isShared(); }
|
||||
void QString::clear()
|
||||
{ if (!isNull()) *this = QString(); }
|
||||
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)
|
||||
{ return setNum(qlonglong(n), base); }
|
||||
QString &QString::setNum(ushort n, int base)
|
||||
@ -1326,20 +1326,20 @@ QString::~QString() {}
|
||||
|
||||
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);
|
||||
if (d->constAllocatedCapacity())
|
||||
d->setFlag(Data::CapacityReserved);
|
||||
if (d.constAllocatedCapacity())
|
||||
d.setFlag(Data::CapacityReserved);
|
||||
}
|
||||
|
||||
void QString::squeeze()
|
||||
{
|
||||
if (!d.isMutable())
|
||||
return;
|
||||
if (d->needsDetach() || size() < capacity())
|
||||
if (d.needsDetach() || size() < capacity())
|
||||
reallocData(d.size, QArrayData::KeepSize);
|
||||
if (d->constAllocatedCapacity())
|
||||
d->clearFlag(Data::CapacityReserved);
|
||||
if (d.constAllocatedCapacity())
|
||||
d.clearFlag(Data::CapacityReserved);
|
||||
}
|
||||
|
||||
QString &QString::setUtf16(const ushort *autf16, qsizetype asize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user