Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #10

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/vibe/container/dictionarylist.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 35 additions & 1 deletion source/vibe/container/internal/utilallocator.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Loading