Skip to content

Commit

Permalink
Merge pull request #10 from vibe-d/improvements
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
s-ludwig authored Feb 15, 2024
2 parents 9044a78 + 4634d7d commit e30802f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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);
}
}

0 comments on commit e30802f

Please sign in to comment.