From fd723148c1c9065d57096c5f45953913abd1b076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 15 Feb 2024 17:24:01 +0100 Subject: [PATCH 1/2] Fix scope related deprecation warning. --- source/vibe/container/dictionarylist.d | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/vibe/container/dictionarylist.d b/source/vibe/container/dictionarylist.d index e6a69a5..14dd298 100644 --- a/source/vibe/container/dictionarylist.d +++ b/source/vibe/container/dictionarylist.d @@ -321,8 +321,8 @@ struct DictionaryList(VALUE, bool case_sensitive = true, size_t NUM_STATIC_FIELD } } - private ptrdiff_t getIndex(in Field[] map, string key, uint keysum) - const { + private ptrdiff_t getIndex(scope const Field[] map, string key, uint keysum) + const scope { foreach (i, ref const(Field) entry; map) { static if (USE_HASHSUM) if (entry.keyCheckSum != keysum) continue; if (matches(entry.key, key)) return i; From 4634d7df1565e9d6413ea510fce3d3d5593ee3d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 15 Feb 2024 17:24:20 +0100 Subject: [PATCH 2/2] Add missing functionality for RegionListAllocator. --- .../vibe/container/internal/utilallocator.d | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/source/vibe/container/internal/utilallocator.d b/source/vibe/container/internal/utilallocator.d index 82cfb6e..f4694cb 100644 --- a/source/vibe/container/internal/utilallocator.d +++ b/source/vibe/container/internal/utilallocator.d @@ -63,7 +63,6 @@ void ensureNotInGC(T)(string info = null) nothrow final class RegionListAllocator(Allocator, bool leak = false) : IAllocator { - import vibe.internal.memory_legacy : AllocSize, alignedSize; import std.algorithm.comparison : min, max; import std.conv : emplace; @@ -228,3 +227,38 @@ final class RegionListAllocator(Allocator, bool leak = false) : IAllocator { return true; } } + +unittest { + auto alloc = new RegionListAllocator!(shared(GCAllocator))(1024, GCAllocator.instance); + auto mem = alloc.allocate(8); + assert(mem.length == 8); + alloc.deallocateAll(); +} + +template AllocSize(T) +{ + static if (is(T == class)) { + // workaround for a strange bug where AllocSize!SSLStream == 0: TODO: dustmite! + enum dummy = T.stringof ~ __traits(classInstanceSize, T).stringof; + enum AllocSize = __traits(classInstanceSize, T); + } else { + enum AllocSize = T.sizeof; + } +} + +enum size_t alignment = 0x10; +enum size_t alignmentMask = alignment-1; + +size_t alignedSize(size_t sz) nothrow +{ + return ((sz + alignment - 1) / alignment) * alignment; +} + +unittest { + foreach( i; 0 .. 20 ){ + auto ia = alignedSize(i); + assert(ia >= i); + assert((ia & alignmentMask) == 0); + assert(ia < i+alignment); + } +}