From 79917d79656d3a217ca4f9a4c24a6d87c5ebc06a Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Thu, 15 Oct 2020 14:37:31 +0200 Subject: [PATCH] QRegularExpression: port to QESDP For QRegularExpressionMatchIterator there is actually one code path that modifies the object itself. Avoid spurious calls to detach() in there by making the detach explicit, and streamline the rest of the code around it. QRegularExpressionMatch only has a const API so it "doesn't care", but port it for consistency. Change-Id: I26881b3af9ae75082dd39462115869b1a9ee1339 Reviewed-by: Thiago Macieira --- src/corelib/text/qregularexpression.cpp | 5 ++--- src/corelib/text/qregularexpression.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp index 45ed3f806a..cd5cd53c55 100644 --- a/src/corelib/text/qregularexpression.cpp +++ b/src/corelib/text/qregularexpression.cpp @@ -2572,9 +2572,8 @@ QRegularExpressionMatch QRegularExpressionMatchIterator::next() return d.constData()->next; } - QRegularExpressionMatch current = d.constData()->next; - d->next = current.d.constData()->nextMatch(); - return current; + d.detach(); + return qExchange(d->next, d->next.d.constData()->nextMatch()); } /*! diff --git a/src/corelib/text/qregularexpression.h b/src/corelib/text/qregularexpression.h index efa9470685..b33c44020f 100644 --- a/src/corelib/text/qregularexpression.h +++ b/src/corelib/text/qregularexpression.h @@ -263,7 +263,7 @@ private: friend class QRegularExpressionMatchIterator; QRegularExpressionMatch(QRegularExpressionMatchPrivate &dd); - QSharedDataPointer d; + QExplicitlySharedDataPointer d; }; Q_DECLARE_SHARED(QRegularExpressionMatch) @@ -308,7 +308,7 @@ private: friend QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIteratorSentinel end(const QRegularExpressionMatchIterator &) { return {}; } QRegularExpressionMatchIterator(QRegularExpressionMatchIteratorPrivate &dd); - QSharedDataPointer d; + QExplicitlySharedDataPointer d; }; namespace QtPrivate {