equal
deleted
inserted
replaced
72 int topLevel; |
72 int topLevel; |
73 int size; |
73 int size; |
74 uint randomBits; |
74 uint randomBits; |
75 uint insertInOrder : 1; |
75 uint insertInOrder : 1; |
76 uint sharable : 1; |
76 uint sharable : 1; |
77 |
77 uint strictAlignment : 1; |
78 static QMapData *createData(); |
78 uint reserved : 29; |
|
79 |
|
80 static QMapData *createData(); // ### Qt5 remove me |
|
81 static QMapData *createData(int alignment); |
79 void continueFreeData(int offset); |
82 void continueFreeData(int offset); |
80 Node *node_create(Node *update[], int offset); |
83 Node *node_create(Node *update[], int offset); // ### Qt5 remove me |
|
84 Node *node_create(Node *update[], int offset, int alignment); |
81 void node_delete(Node *update[], int offset, Node *node); |
85 void node_delete(Node *update[], int offset, Node *node); |
82 #ifdef QT_QMAP_DEBUG |
86 #ifdef QT_QMAP_DEBUG |
83 uint adjust_ptr(Node *node); |
87 uint adjust_ptr(Node *node); |
84 void dump(); |
88 void dump(); |
85 #endif |
89 #endif |
143 QMapData *d; |
147 QMapData *d; |
144 QMapData::Node *e; |
148 QMapData::Node *e; |
145 }; |
149 }; |
146 |
150 |
147 static inline int payload() { return sizeof(PayloadNode) - sizeof(QMapData::Node *); } |
151 static inline int payload() { return sizeof(PayloadNode) - sizeof(QMapData::Node *); } |
|
152 static inline int alignment() { |
|
153 #ifdef Q_ALIGNOF |
|
154 return int(qMax(sizeof(void*), Q_ALIGNOF(Node))); |
|
155 #else |
|
156 return 0; |
|
157 #endif |
|
158 } |
148 static inline Node *concrete(QMapData::Node *node) { |
159 static inline Node *concrete(QMapData::Node *node) { |
149 return reinterpret_cast<Node *>(reinterpret_cast<char *>(node) - payload()); |
160 return reinterpret_cast<Node *>(reinterpret_cast<char *>(node) - payload()); |
150 } |
161 } |
151 |
162 |
152 public: |
163 public: |
412 |
423 |
413 template <class Key, class T> |
424 template <class Key, class T> |
414 Q_INLINE_TEMPLATE typename QMapData::Node * |
425 Q_INLINE_TEMPLATE typename QMapData::Node * |
415 QMap<Key, T>::node_create(QMapData *adt, QMapData::Node *aupdate[], const Key &akey, const T &avalue) |
426 QMap<Key, T>::node_create(QMapData *adt, QMapData::Node *aupdate[], const Key &akey, const T &avalue) |
416 { |
427 { |
417 QMapData::Node *abstractNode = adt->node_create(aupdate, payload()); |
428 QMapData::Node *abstractNode = adt->node_create(aupdate, payload(), alignment()); |
418 QT_TRY { |
429 QT_TRY { |
419 Node *concreteNode = concrete(abstractNode); |
430 Node *concreteNode = concrete(abstractNode); |
420 new (&concreteNode->key) Key(akey); |
431 new (&concreteNode->key) Key(akey); |
421 QT_TRY { |
432 QT_TRY { |
422 new (&concreteNode->value) T(avalue); |
433 new (&concreteNode->value) T(avalue); |
713 |
724 |
714 template <class Key, class T> |
725 template <class Key, class T> |
715 Q_OUTOFLINE_TEMPLATE void QMap<Key, T>::detach_helper() |
726 Q_OUTOFLINE_TEMPLATE void QMap<Key, T>::detach_helper() |
716 { |
727 { |
717 union { QMapData *d; QMapData::Node *e; } x; |
728 union { QMapData *d; QMapData::Node *e; } x; |
718 x.d = QMapData::createData(); |
729 x.d = QMapData::createData(alignment()); |
719 if (d->size) { |
730 if (d->size) { |
720 x.d->insertInOrder = true; |
731 x.d->insertInOrder = true; |
721 QMapData::Node *update[QMapData::LastLevel + 1]; |
732 QMapData::Node *update[QMapData::LastLevel + 1]; |
722 QMapData::Node *cur = e->forward[0]; |
733 QMapData::Node *cur = e->forward[0]; |
723 update[0] = x.e; |
734 update[0] = x.e; |
903 |
914 |
904 #ifndef QT_NO_STL |
915 #ifndef QT_NO_STL |
905 template <class Key, class T> |
916 template <class Key, class T> |
906 Q_OUTOFLINE_TEMPLATE QMap<Key, T>::QMap(const std::map<Key, T> &other) |
917 Q_OUTOFLINE_TEMPLATE QMap<Key, T>::QMap(const std::map<Key, T> &other) |
907 { |
918 { |
908 d = QMapData::createData(); |
919 d = QMapData::createData(alignment()); |
909 d->insertInOrder = true; |
920 d->insertInOrder = true; |
910 typename std::map<Key,T>::const_iterator it = other.end(); |
921 typename std::map<Key,T>::const_iterator it = other.end(); |
911 while (it != other.begin()) { |
922 while (it != other.begin()) { |
912 --it; |
923 --it; |
913 insert((*it).first, (*it).second); |
924 insert((*it).first, (*it).second); |