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>
This commit is contained in:
parent
213f7d1b1f
commit
5f1f0fe0b7
@ -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]));
|
||||
|
@ -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
|
||||
|
@ -135,11 +135,11 @@ void tst_toolsupport::offsets_data()
|
||||
|
||||
{
|
||||
QTest::newRow("QDateTimePrivate::m_msecs")
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_msecs) << 0 << 0;
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_msecs) << 8 << 8;
|
||||
QTest::newRow("QDateTimePrivate::m_status")
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_status) << 8 << 8;
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_status) << 4 << 4;
|
||||
QTest::newRow("QDateTimePrivate::m_offsetFromUtc")
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_offsetFromUtc) << 12 << 12;
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_offsetFromUtc) << 16 << 16;
|
||||
QTest::newRow("QDateTimePrivate::m_timeZone")
|
||||
<< pmm_to_offsetof(&QDateTimePrivate::m_timeZone) << 20 << 24;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user