From a6be2d77aa6dc9f834b971eaff749a02cf982525 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Fri, 7 Oct 2016 13:47:52 +0200 Subject: V4: Move zero-initialization of heap items into the header file This allows for a compiler to do dead-store elimination for zero- initialized memory that gets overwritten directly after the allocated chunk is returned. Change-Id: I6493aae8fdabc2306e7cfa1233f917b1775c4451 Reviewed-by: Simon Hausmann --- src/qml/memory/qv4mm.cpp | 2 +- src/qml/memory/qv4mm_p.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/qml/memory') diff --git a/src/qml/memory/qv4mm.cpp b/src/qml/memory/qv4mm.cpp index ad4ecfe76d..5aaf710ee8 100644 --- a/src/qml/memory/qv4mm.cpp +++ b/src/qml/memory/qv4mm.cpp @@ -234,7 +234,7 @@ bool sweepChunk(MemoryManager::Data::ChunkHeader *header, uint *itemsInUse, Exec m->_checkIsDestroyed(); } - memset(m, 0, header->itemSize); + memset(m, 0, sizeof(Heap::Base)); #ifdef V4_USE_VALGRIND VALGRIND_DISABLE_ERROR_REPORTING; VALGRIND_MEMPOOL_FREE(engine->memoryManager, m); diff --git a/src/qml/memory/qv4mm_p.h b/src/qml/memory/qv4mm_p.h index e68fc07a46..dfa0d85dff 100644 --- a/src/qml/memory/qv4mm_p.h +++ b/src/qml/memory/qv4mm_p.h @@ -111,6 +111,7 @@ public: V4_ASSERT_IS_TRIVIAL(typename ManagedType::Data) size = align(size); Heap::Base *o = allocData(size, unmanagedSize); + memset(o, 0, size); o->setVtable(ManagedType::staticVTable()); return static_cast(o); } -- cgit v1.2.3