summaryrefslogtreecommitdiffstats
path: root/src/sql
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-03-27 19:26:38 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-04-26 19:56:07 +0000
commit204f1764ca6f4b670eaa87a775ded09a72a07aba (patch)
tree0101ae8fd143091df12ddf1274b3e94706cce141 /src/sql
parentf291575d95ab0159fa809c63855f787ccb1877f5 (diff)
QSqlRecord: use QSharedData for private class
Use QSharedData for the private class instead a home-brew version. Change-Id: Id3625bb0eb8f81c9caa672e2453dab3d44b15ea9 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/sql')
-rw-r--r--src/sql/kernel/qsqlrecord.cpp28
-rw-r--r--src/sql/kernel/qsqlrecord.h9
2 files changed, 12 insertions, 25 deletions
diff --git a/src/sql/kernel/qsqlrecord.cpp b/src/sql/kernel/qsqlrecord.cpp
index c9f26e27a1..e4d2c96c6b 100644
--- a/src/sql/kernel/qsqlrecord.cpp
+++ b/src/sql/kernel/qsqlrecord.cpp
@@ -11,23 +11,17 @@
QT_BEGIN_NAMESPACE
-class QSqlRecordPrivate
+class QSqlRecordPrivate : public QSharedData
{
public:
- QSqlRecordPrivate() = default;
- QSqlRecordPrivate(const QSqlRecordPrivate &other)
- : fields(other.fields)
- {
- }
-
inline bool contains(qsizetype index) const
{
return index >= 0 && index < fields.size();
}
QList<QSqlField> fields;
- QAtomicInt ref{1};
};
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QSqlRecordPrivate)
/*!
\class QSqlRecord
@@ -82,10 +76,7 @@ QSqlRecord::QSqlRecord()
*/
QSqlRecord::QSqlRecord(const QSqlRecord& other)
- : d(other.d)
-{
- d->ref.ref();
-}
+ = default;
/*!
\fn QSqlRecord::QSqlRecord(QSqlRecord &&other)
@@ -126,20 +117,15 @@ QSqlRecord::QSqlRecord(const QSqlRecord& other)
*/
QSqlRecord& QSqlRecord::operator=(const QSqlRecord& other)
-{
- QSqlRecord(other).swap(*this);
- return *this;
-}
+ = default;
/*!
Destroys the object and frees any allocated resources.
*/
QSqlRecord::~QSqlRecord()
-{
- if (d && !d->ref.deref())
- delete d;
-}
+ = default;
+
/*!
\fn bool QSqlRecord::operator!=(const QSqlRecord &other) const
@@ -501,7 +487,7 @@ void QSqlRecord::setValue(const QString& name, const QVariant& val)
*/
void QSqlRecord::detach()
{
- qAtomicDetach(d);
+ d.detach();
}
#ifndef QT_NO_DEBUG_STREAM
diff --git a/src/sql/kernel/qsqlrecord.h b/src/sql/kernel/qsqlrecord.h
index 76e6ee982d..2ae7ff38c3 100644
--- a/src/sql/kernel/qsqlrecord.h
+++ b/src/sql/kernel/qsqlrecord.h
@@ -5,6 +5,7 @@
#define QSQLRECORD_H
#include <QtSql/qtsqlglobal.h>
+#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
QT_BEGIN_NAMESPACE
@@ -13,19 +14,19 @@ QT_BEGIN_NAMESPACE
class QSqlField;
class QVariant;
class QSqlRecordPrivate;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QSqlRecordPrivate, Q_SQL_EXPORT)
class Q_SQL_EXPORT QSqlRecord
{
public:
QSqlRecord();
QSqlRecord(const QSqlRecord& other);
- QSqlRecord(QSqlRecord &&other) noexcept
- : d{std::exchange(other.d, nullptr)} {}
+ QSqlRecord(QSqlRecord &&other) noexcept = default;
QSqlRecord& operator=(const QSqlRecord& other);
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSqlRecord)
~QSqlRecord();
- void swap(QSqlRecord &other) noexcept { qt_ptr_swap(d, other.d); }
+ void swap(QSqlRecord &other) noexcept { d.swap(other.d); }
bool operator==(const QSqlRecord &other) const;
inline bool operator!=(const QSqlRecord &other) const { return !operator==(other); }
@@ -65,7 +66,7 @@ public:
private:
void detach();
- QSqlRecordPrivate* d;
+ QExplicitlySharedDataPointer<QSqlRecordPrivate> d;
};
#ifndef QT_NO_DEBUG_STREAM