summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-03-15 14:38:03 +0100
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-03-15 21:13:31 +0100
commit3813e236a8f48babaa850123e3a2a04e80713219 (patch)
treede3caf2cf3186e2e2dbf2472685da545ddf01069 /src/corelib/tools/qlist.h
parent9bf056e3f759ef87aca9c1f481ac3fb28e6599b9 (diff)
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
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h52
1 files changed, 15 insertions, 37 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index e3b8e1b545..67f63f3abc 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(&copy, 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(&copy);
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(&copy, 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(&copy);
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(&copy, 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(&copy);
QT_RETHROW;
}
+ *n = copy;
}
}
}