QDom: optimize an atomic read

By the time setNodeValue() gets its hands on the removed object, the
removeChild() function has already called removed->ref.deref(), which
performs an acquire fence if the ref-count drops to zero.

IOW: if removed->ref == 0 now, then an acquire fence has been
executed. If ref != 0, then we're not reaching into removed, so we
need no acquire.

Therefore, a relaxed load suffices (as opposed to the loadAcquire()
the implicit conversion operator performs).

Found by disabling QAtomic<T> -> T implicit conversions.

Change-Id: I367754fde0ad82db797161b5e94e2ebc08a90c0b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2022-04-04 18:00:36 +02:00
parent ad26d6a18d
commit 2fb7c94f63

View File

@ -3625,7 +3625,7 @@ void QDomAttrPrivate::setNodeValue(const QString& v)
t->ref.deref();
if (first) {
auto removed = removeChild(first);
if (removed && !removed->ref)
if (removed && !removed->ref.loadRelaxed()) // removeChild() already deref()ed
delete removed;
}
appendChild(t);