From eb595ef858b12936f6c2bbfc3b59058410354079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?So=CC=88nke=20Ludwig?= Date: Sat, 26 Aug 2017 22:33:00 +0200 Subject: [PATCH] Fix always calling GC.addRange in ChoppedVector if necessary. --- source/eventcore/internal/utils.d | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/source/eventcore/internal/utils.d b/source/eventcore/internal/utils.d index 04e20dd..70b827e 100644 --- a/source/eventcore/internal/utils.d +++ b/source/eventcore/internal/utils.d @@ -38,9 +38,7 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { @safe: nothrow: import core.stdc.stdlib : calloc, free, malloc, realloc; - import std.traits : hasElaborateDestructor; - - static assert(!hasElaborateDestructor!T, "Cannot store element with elaborate destructor in ChoppedVector."); + import std.traits : hasIndirections; alias chunkSize = CHUNK_SIZE; @@ -65,7 +63,9 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { @nogc { () @trusted { foreach (i; 0 .. m_chunkCount) { - GC.removeRange(m_chunks[i]); + destroy(m_chunks[i]); + static if (hasIndirections!T) + GC.removeRange(m_chunks[i]); free(m_chunks[i]); } free(m_chunks.ptr); @@ -127,7 +127,9 @@ struct ChoppedVector(T, size_t CHUNK_SIZE = 16*64*1024/nextPOT(T.sizeof)) { () @trusted { auto ptr = cast(ChunkPtr)calloc(chunkSize, T.sizeof); assert(ptr !is null, "Failed to allocate chunk!"); - GC.addRange(ptr, chunkSize * T.sizeof); + // FIXME: initialize with T.init instead of 0 + static if (hasIndirections!T) + GC.addRange(ptr, chunkSize * T.sizeof); m_chunks[m_chunkCount++] = ptr; } (); }