diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-01-04 10:49:23 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-01-25 08:30:54 +0000 |
commit | d8c6bf2dc129522f779d2c4ffc698a97b7531f66 (patch) | |
tree | 64b866176576a56b6ddb9c2e841e88796fd7dedb /src/qml/memory/qv4mm.cpp | |
parent | 8acf7385f341752984db280773f167e405b8bc12 (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/qv4mm.cpp')
-rw-r--r-- | src/qml/memory/qv4mm.cpp | 8 |
1 files changed, 6 insertions, 2 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; } |