diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-02-20 10:07:29 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2017-02-22 08:04:12 +0000 |
commit | 19085350fb3b9de89a4c3e5a6c1c7bbb2a43c324 (patch) | |
tree | 6a23805fed9ead17b7a12b07794834edcfe90cdb | |
parent | 4df229ce50d72e814c34b73c14a30c4d3d4724b1 (diff) | |
download | qtbase-19085350fb3b9de89a4c3e5a6c1c7bbb2a43c324.tar.gz |
Do not use QTypeInfo::isStatic anymore
... except in QList.
When dafa3618 introduced isRelocatable and QTypeInfoQuery, the
intention was to decouple the memory layout of QList from the
reallocation optimizations in QVector. This never happened, as
QVector (and QVarLengthArray) continue to use isStatic to this
day.
Fix by porting both QVector and QVLA to QTypeInfoQuery and
isRelocatable.
Change-Id: I6951f2cf21f0cbb24e2dbd38f80f1bd82007d394
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/tools/qlist.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 8 |
3 files changed, 7 insertions, 6 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index c0a92aaa10..f861c1e71c 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -126,6 +126,7 @@ class QList public: struct MemoryLayout : std::conditional< + // must stay isStatic until ### Qt 6 for BC reasons (don't use !isRelocatable)! QTypeInfo<T>::isStatic || QTypeInfo<T>::isLarge, QListData::IndirectLayout, typename std::conditional< diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index bb5ae78d2b..25f5176c22 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -352,7 +352,7 @@ Q_OUTOFLINE_TEMPLATE void QVarLengthArray<T, Prealloc>::realloc(int asize, int a a = Prealloc; } s = 0; - if (QTypeInfo<T>::isStatic) { + if (!QTypeInfoQuery<T>::isRelocatable) { QT_TRY { // copy all the old elements while (s < copySize) { @@ -445,7 +445,7 @@ Q_OUTOFLINE_TEMPLATE typename QVarLengthArray<T, Prealloc>::iterator QVarLengthA if (n != 0) { resize(s + n); const T copy(t); - if (QTypeInfo<T>::isStatic) { + if (!QTypeInfoQuery<T>::isRelocatable) { T *b = ptr + offset; T *j = ptr + s; T *i = j - n; diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 5225b68d40..c69d27bbf9 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -553,7 +553,7 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo T *srcEnd = asize > d->size ? d->end() : d->begin() + asize; T *dst = x->begin(); - if (QTypeInfo<T>::isStatic || (isShared && QTypeInfo<T>::isComplex)) { + if (!QTypeInfoQuery<T>::isRelocatable || (isShared && QTypeInfo<T>::isComplex)) { // we can not move the data, we need to copy construct it while (srcBegin != srcEnd) { new (dst++) T(*srcBegin++); @@ -598,7 +598,7 @@ void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::Allo } if (d != x) { if (!d->ref.deref()) { - if (QTypeInfo<T>::isStatic || !aalloc || (isShared && QTypeInfo<T>::isComplex)) { + if (!QTypeInfoQuery<T>::isRelocatable || !aalloc || (isShared && QTypeInfo<T>::isComplex)) { // data was copy constructed, we need to call destructors // or if !alloc we did nothing to the old 'd'. freeData(d); @@ -697,7 +697,7 @@ typename QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, c const T copy(t); if (!isDetached() || d->size + n > int(d->alloc)) reallocData(d->size, d->size + n, QArrayData::Grow); - if (QTypeInfo<T>::isStatic) { + if (!QTypeInfoQuery<T>::isRelocatable) { T *b = d->end(); T *i = d->end() + n; while (i != b) @@ -746,7 +746,7 @@ typename QVector<T>::iterator QVector<T>::erase(iterator abegin, iterator aend) detach(); abegin = d->begin() + itemsUntouched; aend = abegin + itemsToErase; - if (QTypeInfo<T>::isStatic) { + if (!QTypeInfoQuery<T>::isRelocatable) { iterator moveBegin = abegin + itemsToErase; iterator moveEnd = d->end(); while (moveBegin != moveEnd) { |