Gui: mark types Q_PRIMITIVE_TYPE when they're held in QDataBuffer

QDataBuffer assumes that its template argument is a POD, iow: it's ok
to not run ctors and dtors and assign a value into uninitialized
memory.

In Qt, we call that Q_PRIMITIVE_TYPE. Asserting that the QDataBuffer
value_type is not QTypeInfo::isComplex, however, has shown that a
large number of types had not been marked as such, sometimes for good
reason, e.g. because their default constructor doesn't
value-initialize all members, but sets some of them to -1.

Since QDataBuffer doesn't memset the memory to zero, it doesn't
matter, as the code obviously has to have worked before, with
uninitialized memory, and all-zeros is just a special, if common, form
of uninitialized memory.

I also tried to assert is_pod in QDataBuffer (working around the fact
that that particular trait is deprecated), but found that almost none
of the types in question were, in fact, trivial. We should fix this,
because it means the compiler is generating code that's less efficient
than it could be, but that's for another patch.

All types marked as Q_PRIMITIVE_TYPE in this patch are private API, so
this doesn't affect users.

For PathSimplifier::Event, had to shorten the unnamed namespace to not
include the member functions, because Q_DECLARE_TYPEINFO cannot appear
in a namespace other than the Qt one.

Pick-to: 6.4 6.3
Change-Id: I4431a2f269ec1ac4804a87ea71f983eaa34ef867
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@gmail.com>
This commit is contained in:
Marc Mutz 2022-07-08 08:19:59 +02:00 committed by Tor Arne Vestbø
parent 6b6b88774b
commit 04ab0905e3
4 changed files with 14 additions and 3 deletions

View File

@ -63,6 +63,7 @@ struct QIntersection
QPointF pos;
};
Q_DECLARE_TYPEINFO(QIntersection, Q_PRIMITIVE_TYPE);
class QIntersectionFinder
{

View File

@ -79,6 +79,7 @@ public:
qreal x;
qreal y;
};
Q_DECLARE_TYPEINFO(QPathVertex, Q_PRIMITIVE_TYPE);
class QPathEdge
{
@ -122,6 +123,7 @@ public:
private:
int m_next[2][2] = { { -1, -1 }, { -1, -1 } };
};
Q_DECLARE_TYPEINFO(QPathEdge, Q_PRIMITIVE_TYPE);
class QPathSegments
{
@ -135,6 +137,7 @@ public:
return t < o.t;
}
};
friend class QTypeInfo<Intersection>;
struct Segment {
Segment(int pathId, int vertexA, int vertexB)
@ -156,6 +159,7 @@ public:
QRectF bounds;
};
friend class QTypeInfo<Segment>;
QPathSegments(int reserve);
@ -187,6 +191,8 @@ private:
int m_pathId;
};
Q_DECLARE_TYPEINFO(QPathSegments::Intersection, Q_PRIMITIVE_TYPE);
Q_DECLARE_TYPEINFO(QPathSegments::Segment, Q_PRIMITIVE_TYPE);
class Q_AUTOTEST_EXPORT QWingedEdge
{

View File

@ -303,6 +303,7 @@ private:
Type type;
Element *element;
};
friend class QTypeInfo<Event>;
typedef QRBTree<Element *>::Node RBNode;
typedef BoundingVolumeHierarchy::Node BVHNode;
@ -341,6 +342,10 @@ private:
uint m_hints;
};
} // unnamed namespace
Q_DECLARE_TYPEINFO(PathSimplifier::Event, Q_PRIMITIVE_TYPE);
inline PathSimplifier::BoundingVolumeHierarchy::BoundingVolumeHierarchy()
: root(nullptr)
, nodeBlock(nullptr)
@ -1614,9 +1619,6 @@ void PathSimplifier::sortEvents(Event *events, int count)
}
}
} // end anonymous namespace
void qSimplifyPath(const QVectorPath &path, QDataBuffer<QPoint> &vertices,
QDataBuffer<quint32> &indices, const QTransform &matrix)
{

View File

@ -41,6 +41,7 @@ public:
operator QPointF() {return QPointF(x,y);}
operator QPointF() const {return QPointF(x,y);}
};
Q_DECLARE_TYPEINFO(QOpenGLPoint, Q_PRIMITIVE_TYPE);
struct QOpenGLRect
{
@ -57,6 +58,7 @@ struct QOpenGLRect
operator QRectF() const {return QRectF(left, top, right-left, bottom-top);}
};
Q_DECLARE_TYPEINFO(QOpenGLRect, Q_PRIMITIVE_TYPE);
class QOpenGL2PEXVertexArray
{