diff options
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qcoreevent.cpp | 32 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreevent.h | 29 |
2 files changed, 23 insertions, 38 deletions
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 847f3227ea..86d43d2d96 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -295,9 +295,8 @@ QT_BEGIN_NAMESPACE Contructs an event object of type \a type. */ QEvent::QEvent(Type type) - : d(nullptr), t(type), m_posted(false), m_spont(false), m_accept(true), - m_inputEvent(false), m_pointerEvent(false), m_singlePointEvent(false), - m_reserved(0) + : t(type), m_reserved(0), + m_inputEvent(false), m_pointerEvent(false), m_singlePointEvent(false) { Q_TRACE(QEvent_ctor, this, t); } @@ -306,17 +305,7 @@ QEvent::QEvent(Type type) \internal Copies the \a other event. */ -QEvent::QEvent(const QEvent &other) - : d(other.d), t(other.t), m_posted(other.m_posted), m_spont(other.m_spont), - m_accept(other.m_accept), m_inputEvent(other.m_inputEvent), - m_pointerEvent(other.m_pointerEvent), m_singlePointEvent(other.m_singlePointEvent), - m_reserved(other.m_reserved) -{ - Q_TRACE(QEvent_ctor, this, t); - // if QEventPrivate becomes available, make sure to implement a - // virtual QEventPrivate *clone() const; function so we can copy here - Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere"); -} +QEvent::QEvent(const QEvent &other) = default; /*! \internal @@ -351,18 +340,7 @@ QEvent::QEvent(const QEvent &other) Copying events is a bad idea, yet some Qt 4 code does it (notably, QApplication and the state machine). */ -QEvent &QEvent::operator=(const QEvent &other) -{ - // if QEventPrivate becomes available, make sure to implement a - // virtual QEventPrivate *clone() const; function so we can copy here - Q_ASSERT_X(!other.d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere"); - - t = other.t; - m_posted = other.m_posted; - m_spont = other.m_spont; - m_accept = other.m_accept; - return *this; -} +QEvent &QEvent::operator=(const QEvent &other) = default; /*! Destroys the event. If it was \l{QCoreApplication::postEvent()}{posted}, diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index dbca4adaab..cfaa959dec 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -320,27 +320,34 @@ protected: QEvent(Type type, PointerEventTag) : QEvent(type, InputEventTag{}) { m_pointerEvent = true; } struct SinglePointEventTag { explicit SinglePointEventTag() = default; }; QEvent(Type type, SinglePointEventTag) : QEvent(type, PointerEventTag{}) { m_singlePointEvent = true; } - QEventPrivate *d; + QEventPrivate *d = nullptr; quint16 t; private: - quint16 m_posted : 1; - quint16 m_spont : 1; - quint16 m_accept : 1; + /* + We can assume that C++ types are 8-byte aligned, and we can't assume that compilers + coalesce data members from subclasses. Use bitfields to fill up to next 8-byte + aligned size, which is 24 bytes. That way we don't waste memory, and have plenty of room + for future flags. + Don't use bitfields for the most important flags, as that would generate more code, and + access is always inline. Bytes used are: + 8 vptr + 8 d-pointer + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, + compiler will add padding after the booleans, so add another unused bool, which leaves + us with 16 bits. + */ + bool m_posted = false; + bool m_spont = false; + bool m_accept = true; + bool m_unused = false; + quint16 m_reserved : 13; quint16 m_inputEvent : 1; quint16 m_pointerEvent : 1; quint16 m_singlePointEvent : 1; - quint16 m_reserved : 10; friend class QCoreApplication; friend class QCoreApplicationPrivate; friend class QThreadData; friend class QApplication; -#if QT_CONFIG(shortcut) - friend class QShortcutMap; -#endif - friend class QGraphicsView; - friend class QGraphicsScene; friend class QGraphicsScenePrivate; // from QtTest: friend class QSpontaneKeyEvent; |