summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qmap.cpp')
-rw-r--r--src/corelib/tools/qmap.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 13858107e3..3b48c3f24f 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -53,11 +53,16 @@ QT_BEGIN_NAMESPACE
QMapData QMapData::shared_null = {
&shared_null,
{ &shared_null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
- Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, 0, false, true
+ Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0, 0, false, true, false, 0
};
QMapData *QMapData::createData()
{
+ return createData(0);
+}
+
+QMapData *QMapData::createData(int alignment)
+{
QMapData *d = new QMapData;
Q_CHECK_PTR(d);
Node *e = reinterpret_cast<Node *>(d);
@@ -69,6 +74,8 @@ QMapData *QMapData::createData()
d->randomBits = 0;
d->insertInOrder = false;
d->sharable = true;
+ d->strictAlignment = alignment > 8;
+ d->reserved = 0;
return d;
}
@@ -80,11 +87,19 @@ void QMapData::continueFreeData(int offset)
while (cur != e) {
prev = cur;
cur = cur->forward[0];
- qFree(reinterpret_cast<char *>(prev) - offset);
+ if (strictAlignment)
+ qFreeAligned(reinterpret_cast<char *>(prev) - offset);
+ else
+ qFree(reinterpret_cast<char *>(prev) - offset);
}
delete this;
}
+QMapData::Node *QMapData::node_create(Node *update[], int offset)
+{
+ return node_create(update, offset, 0);
+}
+
/*!
Creates a new node inside the data structure.
@@ -94,10 +109,12 @@ void QMapData::continueFreeData(int offset)
\a offset is an amount of bytes that needs to reserved just before the
QMapData::Node structure.
+ \a alignment dictates the alignment for the data.
+
\internal
\since 4.6
*/
-QMapData::Node *QMapData::node_create(Node *update[], int offset)
+QMapData::Node *QMapData::node_create(Node *update[], int offset, int alignment)
{
int level = 0;
uint mask = (1 << Sparseness) - 1;
@@ -118,7 +135,9 @@ QMapData::Node *QMapData::node_create(Node *update[], int offset)
if (level == 3 && !insertInOrder)
randomBits = qrand();
- void *concreteNode = qMalloc(offset + sizeof(Node) + level * sizeof(Node *));
+ void *concreteNode = strictAlignment ?
+ qMallocAligned(offset + sizeof(Node) + level * sizeof(Node *), alignment) :
+ qMalloc(offset + sizeof(Node) + level * sizeof(Node *));
Q_CHECK_PTR(concreteNode);
Node *abstractNode = reinterpret_cast<Node *>(reinterpret_cast<char *>(concreteNode) + offset);
@@ -145,7 +164,10 @@ void QMapData::node_delete(Node *update[], int offset, Node *node)
update[i]->forward[i] = node->forward[i];
}
--size;
- qFree(reinterpret_cast<char *>(node) - offset);
+ if (strictAlignment)
+ qFreeAligned(reinterpret_cast<char *>(node) - offset);
+ else
+ qFree(reinterpret_cast<char *>(node) - offset);
}
#ifdef QT_QMAP_DEBUG