diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-06-26 20:56:40 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-07 20:09:13 +0000 |
commit | 5f1f0fe0b71c19be041ec85a9449584649c9fc18 (patch) | |
tree | ea944c45471eaa41ed803b0726ced78b4895b4b0 /src | |
parent | 213f7d1b1f89a55cc10fb8355cac87927d038f00 (diff) |
QDateTimePrivate: inherit QSharedData and other cleanups
Don't manage the ref-count yourself, as this requires the code to use
the QAtomic copy ctor, which we want to remove going forward. Using
QSharedData, we can let the compiler write the code for us.
Since 'ref' this way moves to the first spot in the list of effective
members, creating a 4B hole between itself and 'msecs', swap 'status'
and 'msecs' to fill the hole:
offset: 0 8 16 24
| | | |
without v v v v
adj.mnt: |*R*| | msecs | S | U | TZ....
before: | msecs | S | U |*R*| | TZ...
after: |*R*| S | msecs | U | | TZ....
This keeps the padding out of the critical first word, which improves
latency. That said, for accessing the members the old layout surely was
optimal. This layout optimizes copies and pessimizes access to 'msecs'
on 32-bit platforms without the Critical Word First optimization.
Requires adjustments to tst_toolsupport and the qhooks version.
Also default members using NSDMI, consequently drop the manual default
ctor.
Change-Id: I3c48e68694ad29b28a13aa47ea0f283fae52edd7
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/global/qhooks.cpp | 2 | ||||
-rw-r--r-- | src/corelib/time/qdatetime_p.h | 18 |
2 files changed, 6 insertions, 14 deletions
diff --git a/src/corelib/global/qhooks.cpp b/src/corelib/global/qhooks.cpp index 020dee3710..79f9b7d6c2 100644 --- a/src/corelib/global/qhooks.cpp +++ b/src/corelib/global/qhooks.cpp @@ -67,7 +67,7 @@ quintptr Q_CORE_EXPORT qtHookData[] = { // The required sizes and offsets are tested in tests/auto/other/toolsupport. // When this fails and the change was intentional, adjust the test and // adjust this value here. - 17 + 18 }; Q_STATIC_ASSERT(QHooks::LastHookIndex == sizeof(qtHookData) / sizeof(qtHookData[0])); diff --git a/src/corelib/time/qdatetime_p.h b/src/corelib/time/qdatetime_p.h index 6e4120d762..f4f00a8b9b 100644 --- a/src/corelib/time/qdatetime_p.h +++ b/src/corelib/time/qdatetime_p.h @@ -56,7 +56,7 @@ #include "qplatformdefs.h" #include "QtCore/qatomic.h" #include "QtCore/qdatetime.h" -#include "QtCore/qpair.h" +#include "QtCore/qshareddata.h" #if QT_CONFIG(timezone) #include "qtimezone.h" @@ -64,7 +64,7 @@ QT_BEGIN_NAMESPACE -class QDateTimePrivate +class QDateTimePrivate : public QSharedData { public: // forward the declarations from QDateTime (this makes them public) @@ -110,13 +110,6 @@ public: DaylightMask = SetToStandardTime | SetToDaylightTime }; - QDateTimePrivate() : m_msecs(0), - m_status(StatusFlag(Qt::LocalTime << TimeSpecShift)), - m_offsetFromUtc(0), - ref(0) - { - } - static QDateTime::Data create(const QDate &toDate, const QTime &toTime, Qt::TimeSpec toSpec, int offsetSeconds); @@ -124,10 +117,9 @@ public: static QDateTime::Data create(const QDate &toDate, const QTime &toTime, const QTimeZone & timeZone); #endif // timezone - qint64 m_msecs; - StatusFlags m_status; - int m_offsetFromUtc; - mutable QAtomicInt ref; + StatusFlags m_status = StatusFlag(Qt::LocalTime << TimeSpecShift); + qint64 m_msecs = 0; + int m_offsetFromUtc = 0; #if QT_CONFIG(timezone) QTimeZone m_timeZone; #endif // timezone |