Drop the d-pointer of QEvent

It's not been used ever since it was added in the Qt 2 days, other than
a hack in QGraphicsView that could be solved more elegantly.

With this change, QEvent is only 16 bytes large, which is nicely aligned
with C++'s default operator new alignment, and we still have
plenty of bits (plus an unused bool) left for extensions.

Change-Id: If9376d90b92983db7fc12575f3893064a1797adf
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
bb10
Volker Hilsheimer 2020-11-11 00:15:25 +01:00
parent d5ae51e0f5
commit 062ba97f86
2 changed files with 4 additions and 7 deletions

View File

@ -349,10 +349,8 @@ QEvent &QEvent::operator=(const QEvent &other) = default;
QEvent::~QEvent()
{
Q_TRACE(QEvent_dtor, this, t);
if (m_posted && QCoreApplication::instance())
QCoreApplicationPrivate::removePostedEvent(this);
Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
}

View File

@ -320,20 +320,19 @@ 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 = nullptr;
quint16 t;
private:
/*
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
aligned size, which is 16 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.
8 vptr + 2 type + 3 bool flags => 3 bytes left, so 24 bits. However, compilers will word-
align the quint16s after the bools, so add another unused bool to fill that gap, which
leaves us with 16 bits.
*/
bool m_posted = false;
bool m_spont = false;