diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-03-15 13:38:03 (GMT) |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-03-15 20:13:31 (GMT) |
commit | 3813e236a8f48babaa850123e3a2a04e80713219 (patch) | |
tree | de3caf2cf3186e2e2dbf2472685da545ddf01069 | |
parent | 9bf056e3f759ef87aca9c1f481ac3fb28e6599b9 (diff) | |
download | Qt-3813e236a8f48babaa850123e3a2a04e80713219.zip Qt-3813e236a8f48babaa850123e3a2a04e80713219.tar.gz Qt-3813e236a8f48babaa850123e3a2a04e80713219.tar.bz2 |
different approach to fixing "the other" aliasing issue
instead of copying the original value and constructing a Node
later, construct a Node immediately and copy it later.
Reviewed-by: thiago
-rw-r--r-- | src/corelib/tools/qlist.h | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index e3b8e1b..67f63f3 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -98,25 +98,6 @@ struct Q_CORE_EXPORT QListData { inline void **end() const { return d->array + d->end; } }; -////////////////////////////////////////////////////////////////////////////////// -// -// QtPodForSize and QtPodForType are internal and may change or go away any time. -// We mean it. -// -////////////////////////////////////////////////////////////////////////////////// -template <int N> struct QtPodForSize { - // This base type is rather obviously broken and cannot be made - // working due to alignment constraints. - // This doesn't matter as far as QList is concerned, as we are - // using this type only for QTypeInfo<T>::isLarge == false. - typedef struct { } Type; -}; -template <> struct QtPodForSize<1> { typedef quint8 Type; }; -template <> struct QtPodForSize<2> { typedef quint16 Type; }; -template <> struct QtPodForSize<4> { typedef quint32 Type; }; -template <> struct QtPodForSize<8> { typedef quint64 Type; }; -template <class T> struct QtPodForType : QtPodForSize<sizeof(T)> { }; - template <typename T> class QList { @@ -529,16 +510,15 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::append(const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType<T>::Type PodNode; - PodNode cpy = *reinterpret_cast<const PodNode *>(&t); - Node *n = reinterpret_cast<Node *>(p.append()); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast<T *>(ptr)); + n = reinterpret_cast<Node *>(p.append());; } QT_CATCH(...) { - --d->end; + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -564,16 +544,15 @@ inline void QList<T>::prepend(const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType<T>::Type PodNode; - PodNode cpy = *reinterpret_cast<const PodNode *>(&t); - Node *n = reinterpret_cast<Node *>(p.prepend()); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast<T *>(ptr)); + n = reinterpret_cast<Node *>(p.prepend());; } QT_CATCH(...) { - ++d->begin; + node_destruct(©); QT_RETHROW; } + *n = copy; } } } @@ -599,16 +578,15 @@ inline void QList<T>::insert(int i, const T &t) QT_RETHROW; } } else { - typedef typename QtPodForType<T>::Type PodNode; - PodNode cpy = *reinterpret_cast<const PodNode *>(&t); - Node *n = reinterpret_cast<Node *>(p.insert(i)); + Node *n, copy; + node_construct(©, t); // t might be a reference to an object in the array QT_TRY { - void *ptr = &cpy; - node_construct(n, *reinterpret_cast<T *>(ptr)); + n = reinterpret_cast<Node *>(p.insert(i));; } QT_CATCH(...) { - p.remove(i); + node_destruct(©); QT_RETHROW; } + *n = copy; } } } |