QCborValue: use assignContainer() in few more places

Change-Id: I5e52dc5b093c43a3b678fffd16b6eb65ef37399d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Thiago Macieira 2021-11-12 13:58:57 -08:00
parent ccea344640
commit f276f9ec6b

View File

@ -772,6 +772,7 @@ static QCborContainerPrivate *assignContainer(QCborContainerPrivate *&d, QCborCo
return d; return d;
if (d) if (d)
d->deref(); d->deref();
if (x)
x->ref.ref(); x->ref.ref();
return d = x; return d = x;
} }
@ -1911,13 +1912,8 @@ void QCborValue::dispose()
*/ */
QCborValue &QCborValue::operator=(const QCborValue &other) QCborValue &QCborValue::operator=(const QCborValue &other)
{ {
if (other.container)
other.container->ref.ref();
if (container)
container->deref();
n = other.n; n = other.n;
container = other.container; assignContainer(container, other.container);
t = other.t; t = other.t;
return *this; return *this;
} }
@ -2276,16 +2272,11 @@ static QCborContainerPrivate *maybeGrow(QCborContainerPrivate *container, qsizet
{ {
auto replace = QCborContainerPrivate::grow(container, index); auto replace = QCborContainerPrivate::grow(container, index);
Q_ASSERT(replace); Q_ASSERT(replace);
if (replace != container) {
if (container)
container->deref();
replace->ref.ref();
}
if (replace->elements.size() == index) if (replace->elements.size() == index)
replace->append(Undefined()); replace->append(Undefined());
else else
Q_ASSERT(replace->elements.size() > index); Q_ASSERT(replace->elements.size() > index);
return replace; return assignContainer(container, replace);
} }
template <typename KeyType> inline QCborValueRef template <typename KeyType> inline QCborValueRef