aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/memory
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-01-04 10:49:23 +0100
committerLars Knoll <lars.knoll@qt.io>2017-01-25 08:30:54 +0000
commitd8c6bf2dc129522f779d2c4ffc698a97b7531f66 (patch)
tree64b866176576a56b6ddb9c2e841e88796fd7dedb /src/qml/memory
parent8acf7385f341752984db280773f167e405b8bc12 (diff)
Let allocData/allocString return 0 initialized memory
There's no point in having the memset inline. In theory, the compiler could optimize by combining this with later on inline initialization code, in practice this doesn't happen anyway, and we have some options of avoiding or combing the memsets in the allocator. Change-Id: I4502ef947ae235223726269821f9482ad62e1070 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/memory')
-rw-r--r--src/qml/memory/qv4mm.cpp8
-rw-r--r--src/qml/memory/qv4mm_p.h2
2 files changed, 6 insertions, 4 deletions
diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp
index b07ca747cd..4cad197d32 100644
--- a/src/qml/memory/qv4mm.cpp
+++ b/src/qml/memory/qv4mm.cpp
@@ -627,6 +627,7 @@ Heap::Base *MemoryManager::allocString(std::size_t unmanagedSize)
if (aggressiveGC)
runGC();
+ const uint stringSize = align(sizeof(Heap::String));
unmanagedHeapSize += unmanagedSize;
bool didGCRun = false;
if (unmanagedHeapSize > unmanagedHeapSizeGCLimit) {
@@ -641,13 +642,14 @@ Heap::Base *MemoryManager::allocString(std::size_t unmanagedSize)
didGCRun = true;
}
- HeapItem *m = blockAllocator.allocate(align(sizeof(Heap::String)));
+ HeapItem *m = blockAllocator.allocate(stringSize);
if (!m) {
if (!didGCRun && shouldRunGC())
runGC();
- m = blockAllocator.allocate(align(sizeof(Heap::String)), true);
+ m = blockAllocator.allocate(stringSize, true);
}
+ memset(m, 0, stringSize);
return *m;
}
@@ -673,6 +675,8 @@ Heap::Base *MemoryManager::allocData(std::size_t size)
runGC();
m = blockAllocator.allocate(size, true);
}
+
+ memset(m, 0, size);
return *m;
}
diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h
index 9cb71e70de..7517328b37 100644
--- a/src/qml/memory/qv4mm_p.h
+++ b/src/qml/memory/qv4mm_p.h
@@ -217,7 +217,6 @@ public:
V4_ASSERT_IS_TRIVIAL(typename ManagedType::Data)
size = align(size);
Heap::Base *o = allocData(size);
- memset(o, 0, size);
o->setVtable(ManagedType::staticVTable());
return static_cast<typename ManagedType::Data *>(o);
}
@@ -251,7 +250,6 @@ public:
typename ManagedType::Data *allocWithStringData(std::size_t unmanagedSize, Arg1 arg1)
{
typename ManagedType::Data *o = reinterpret_cast<typename ManagedType::Data *>(allocString(unmanagedSize));
- memset(o, 0, sizeof(sizeof(typename ManagedType::Data)));
o->setVtable(ManagedType::staticVTable());
o->init(this, arg1);
return o;