From 40d6e8adf5e3cc45b3bd4a94ad3b57f9444e447f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Oct 2014 10:56:14 +0200 Subject: QList: prepare for tag dispatching based on memory layout Add one tag class for each of QList's three different memory layouts to QListData, and inherit QList::MemoryLayout from exactly one of them. To simplify overloading, added tag classes that express the negation of the two extreme poles of memory layout (C-compatible and heap), too. The "missing" one could be added when needed, too. Change-Id: I45ea603731499fd3fdfb37d60a0a98fb22ac15ec Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/corelib') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 023dafb223..255816d0ba 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -66,6 +66,14 @@ template struct QListSpecialMethods { }; template <> struct QListSpecialMethods; struct Q_CORE_EXPORT QListData { + // tags for tag-dispatching of QList implementations, + // based on QList's three different memory layouts: + struct NotArrayCompatibleLayout {}; + struct NotIndirectLayout {}; + struct ArrayCompatibleLayout : NotIndirectLayout {}; // data laid out like a C array + struct InlineWithPaddingLayout : NotArrayCompatibleLayout, NotIndirectLayout {}; // data laid out like a C array with padding + struct IndirectLayout : NotArrayCompatibleLayout {}; // data allocated on the heap + struct Data { QtPrivate::RefCount ref; int alloc, begin, end; @@ -99,6 +107,17 @@ struct Q_CORE_EXPORT QListData { template class QList : public QListSpecialMethods { +public: + struct MemoryLayout + : QtPrivate::if_< + QTypeInfo::isStatic || QTypeInfo::isLarge, + QListData::IndirectLayout, + typename QtPrivate::if_< + sizeof(T) == sizeof(void*), + QListData::ArrayCompatibleLayout, + QListData::InlineWithPaddingLayout + >::type>::type {}; +private: struct Node { void *v; #if defined(Q_CC_BOR) Q_INLINE_TEMPLATE T &t(); -- cgit v1.2.3