src/corelib/tools/qmap.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/corelib/tools/qmap.h	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/corelib/tools/qmap.h	Tue Feb 02 00:43:10 2010 +0200
@@ -74,10 +74,14 @@
     uint randomBits;
     uint insertInOrder : 1;
     uint sharable : 1;
+    uint strictAlignment : 1;
+    uint reserved : 29;
 
-    static QMapData *createData();
+    static QMapData *createData(); // ### Qt5 remove me
+    static QMapData *createData(int alignment);
     void continueFreeData(int offset);
-    Node *node_create(Node *update[], int offset);
+    Node *node_create(Node *update[], int offset); // ### Qt5 remove me
+    Node *node_create(Node *update[], int offset, int alignment);
     void node_delete(Node *update[], int offset, Node *node);
 #ifdef QT_QMAP_DEBUG
     uint adjust_ptr(Node *node);
@@ -145,6 +149,13 @@
     };
 
     static inline int payload() { return sizeof(PayloadNode) - sizeof(QMapData::Node *); }
+    static inline int alignment() {
+#ifdef Q_ALIGNOF
+        return int(qMax(sizeof(void*), Q_ALIGNOF(Node)));
+#else
+        return 0;
+#endif
+    }
     static inline Node *concrete(QMapData::Node *node) {
         return reinterpret_cast<Node *>(reinterpret_cast<char *>(node) - payload());
     }
@@ -414,7 +425,7 @@
 Q_INLINE_TEMPLATE typename QMapData::Node *
 QMap<Key, T>::node_create(QMapData *adt, QMapData::Node *aupdate[], const Key &akey, const T &avalue)
 {
-    QMapData::Node *abstractNode = adt->node_create(aupdate, payload());
+    QMapData::Node *abstractNode = adt->node_create(aupdate, payload(), alignment());
     QT_TRY {
         Node *concreteNode = concrete(abstractNode);
         new (&concreteNode->key) Key(akey);
@@ -715,7 +726,7 @@
 Q_OUTOFLINE_TEMPLATE void QMap<Key, T>::detach_helper()
 {
     union { QMapData *d; QMapData::Node *e; } x;
-    x.d = QMapData::createData();
+    x.d = QMapData::createData(alignment());
     if (d->size) {
         x.d->insertInOrder = true;
         QMapData::Node *update[QMapData::LastLevel + 1];
@@ -905,7 +916,7 @@
 template <class Key, class T>
 Q_OUTOFLINE_TEMPLATE QMap<Key, T>::QMap(const std::map<Key, T> &other)
 {
-    d = QMapData::createData();
+    d = QMapData::createData(alignment());
     d->insertInOrder = true;
     typename std::map<Key,T>::const_iterator it = other.end();
     while (it != other.begin()) {