summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qhash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qhash.h')
-rw-r--r--src/corelib/tools/qhash.h37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index b65f1d3f74..1918229533 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -125,12 +125,15 @@ struct Q_CORE_EXPORT QHashData
short numBits;
int numBuckets;
uint sharable : 1;
+ uint strictAlignment : 1;
+ uint reserved : 30;
- void *allocateNode();
+ void *allocateNode(); // ### Qt5 remove me
+ void *allocateNode(int nodeAlign);
void freeNode(void *node);
QHashData *detach_helper(void (*node_duplicate)(Node *, void *), int nodeSize); // ### Qt5 remove me
- QHashData *detach_helper(void (*node_duplicate)(Node *, void *), void (*node_delete)(Node *),
- int nodeSize);
+ QHashData *detach_helper2(void (*node_duplicate)(Node *, void *), void (*node_delete)(Node *),
+ int nodeSize, int nodeAlign);
void mightGrow();
bool willGrow();
void hasShrunk();
@@ -267,6 +270,14 @@ class QHash
return reinterpret_cast<Node *>(node);
}
+#ifdef Q_ALIGNOF
+ static inline int alignOfNode() { return qMax<int>(sizeof(void*), Q_ALIGNOF(Node)); }
+ static inline int alignOfDummyNode() { return qMax<int>(sizeof(void*), Q_ALIGNOF(DummyNode)); }
+#else
+ static inline int alignOfNode() { return 0; }
+ static inline int alignOfDummyNode() { return 0; }
+#endif
+
public:
inline QHash() : d(&QHashData::shared_null) { d->ref.ref(); }
inline QHash(const QHash<Key, T> &other) : d(other.d) { d->ref.ref(); if (!d->sharable) detach(); }
@@ -483,7 +494,7 @@ private:
Node **findNode(const Key &key, uint *hp = 0) const;
Node *createNode(uint h, const Key &key, const T &value, Node **nextNode);
void deleteNode(Node *node);
- static void deleteNode(QHashData::Node *node);
+ static void deleteNode2(QHashData::Node *node);
static void duplicateNode(QHashData::Node *originalNode, void *newNode);
};
@@ -492,12 +503,12 @@ private:
template <class Key, class T>
Q_INLINE_TEMPLATE void QHash<Key, T>::deleteNode(Node *node)
{
- deleteNode(reinterpret_cast<QHashData::Node*>(node));
+ deleteNode2(reinterpret_cast<QHashData::Node*>(node));
+ d->freeNode(node);
}
-
template <class Key, class T>
-Q_INLINE_TEMPLATE void QHash<Key, T>::deleteNode(QHashData::Node *node)
+Q_INLINE_TEMPLATE void QHash<Key, T>::deleteNode2(QHashData::Node *node)
{
#ifdef Q_CC_BOR
concrete(node)->~QHashNode<Key, T>();
@@ -506,7 +517,6 @@ Q_INLINE_TEMPLATE void QHash<Key, T>::deleteNode(QHashData::Node *node)
#else
concrete(node)->~Node();
#endif
- qFree(node);
}
template <class Key, class T>
@@ -527,9 +537,9 @@ QHash<Key, T>::createNode(uint ah, const Key &akey, const T &avalue, Node **anex
Node *node;
if (QTypeInfo<T>::isDummy) {
- node = reinterpret_cast<Node *>(new (d->allocateNode()) DummyNode(akey));
+ node = reinterpret_cast<Node *>(new (d->allocateNode(alignOfDummyNode())) DummyNode(akey));
} else {
- node = new (d->allocateNode()) Node(akey, avalue);
+ node = new (d->allocateNode(alignOfNode())) Node(akey, avalue);
}
node->h = ah;
@@ -554,7 +564,7 @@ Q_INLINE_TEMPLATE QHash<Key, T> &QHash<Key, T>::unite(const QHash<Key, T> &other
template <class Key, class T>
Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::freeData(QHashData *x)
{
- x->free_helper(deleteNode);
+ x->free_helper(deleteNode2);
}
template <class Key, class T>
@@ -566,8 +576,9 @@ Q_INLINE_TEMPLATE void QHash<Key, T>::clear()
template <class Key, class T>
Q_OUTOFLINE_TEMPLATE void QHash<Key, T>::detach_helper()
{
- QHashData *x = d->detach_helper(duplicateNode, deleteNode,
- QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node));
+ QHashData *x = d->detach_helper2(duplicateNode, deleteNode2,
+ QTypeInfo<T>::isDummy ? sizeof(DummyNode) : sizeof(Node),
+ QTypeInfo<T>::isDummy ? alignOfDummyNode() : alignOfNode());
if (!d->ref.deref())
freeData(d);
d = x;