Skip to content

Commit e30802f

Browse files
authored
Merge pull request #10 from vibe-d/improvements
Improvements
2 parents 9044a78 + 4634d7d commit e30802f

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

source/vibe/container/dictionarylist.d

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ struct DictionaryList(VALUE, bool case_sensitive = true, size_t NUM_STATIC_FIELD
321321
}
322322
}
323323

324-
private ptrdiff_t getIndex(in Field[] map, string key, uint keysum)
325-
const {
324+
private ptrdiff_t getIndex(scope const Field[] map, string key, uint keysum)
325+
const scope {
326326
foreach (i, ref const(Field) entry; map) {
327327
static if (USE_HASHSUM) if (entry.keyCheckSum != keysum) continue;
328328
if (matches(entry.key, key)) return i;

source/vibe/container/internal/utilallocator.d

+35-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ void ensureNotInGC(T)(string info = null) nothrow
6363

6464

6565
final class RegionListAllocator(Allocator, bool leak = false) : IAllocator {
66-
import vibe.internal.memory_legacy : AllocSize, alignedSize;
6766
import std.algorithm.comparison : min, max;
6867
import std.conv : emplace;
6968

@@ -228,3 +227,38 @@ final class RegionListAllocator(Allocator, bool leak = false) : IAllocator {
228227
return true;
229228
}
230229
}
230+
231+
unittest {
232+
auto alloc = new RegionListAllocator!(shared(GCAllocator))(1024, GCAllocator.instance);
233+
auto mem = alloc.allocate(8);
234+
assert(mem.length == 8);
235+
alloc.deallocateAll();
236+
}
237+
238+
template AllocSize(T)
239+
{
240+
static if (is(T == class)) {
241+
// workaround for a strange bug where AllocSize!SSLStream == 0: TODO: dustmite!
242+
enum dummy = T.stringof ~ __traits(classInstanceSize, T).stringof;
243+
enum AllocSize = __traits(classInstanceSize, T);
244+
} else {
245+
enum AllocSize = T.sizeof;
246+
}
247+
}
248+
249+
enum size_t alignment = 0x10;
250+
enum size_t alignmentMask = alignment-1;
251+
252+
size_t alignedSize(size_t sz) nothrow
253+
{
254+
return ((sz + alignment - 1) / alignment) * alignment;
255+
}
256+
257+
unittest {
258+
foreach( i; 0 .. 20 ){
259+
auto ia = alignedSize(i);
260+
assert(ia >= i);
261+
assert((ia & alignmentMask) == 0);
262+
assert(ia < i+alignment);
263+
}
264+
}

0 commit comments

Comments
 (0)