Loop.maxEvents is const, not inout const

This commit is contained in:
Eugen Wissner 2017-01-12 10:43:02 +01:00
parent cb6cc65113
commit 8ddea0aa46
4 changed files with 17 additions and 26 deletions

View File

@ -46,7 +46,7 @@ class EpollLoop : SelectorLoop
{ {
if ((fd = epoll_create1(EPOLL_CLOEXEC)) < 0) if ((fd = epoll_create1(EPOLL_CLOEXEC)) < 0)
{ {
throw MmapPool.instance.make!BadLoopException("epoll initialization failed"); throw defaultAllocator.make!BadLoopException("epoll initialization failed");
} }
super(); super();
events = Vector!epoll_event(maxEvents, MmapPool.instance); events = Vector!epoll_event(maxEvents, MmapPool.instance);

View File

@ -124,8 +124,8 @@ class KqueueLoop : SelectorLoop
* Returns: Maximal event count can be got at a time * Returns: Maximal event count can be got at a time
* (should be supported by the backend). * (should be supported by the backend).
*/ */
override protected @property inout(uint) maxEvents() override protected @property uint maxEvents()
inout const pure nothrow @safe @nogc const pure nothrow @safe @nogc
{ {
return cast(uint) events.length; return cast(uint) events.length;
} }
@ -158,12 +158,12 @@ class KqueueLoop : SelectorLoop
changes.length = changeCount + maxEvents; changes.length = changeCount + maxEvents;
} }
EV_SET(&changes[changeCount], EV_SET(&changes[changeCount],
cast(ulong) socket, cast(ulong) socket,
filter, filter,
flags, flags,
0U, 0U,
0L, 0L,
null); null);
++changeCount; ++changeCount;
} }

View File

@ -137,8 +137,8 @@ abstract class Loop
* Returns: Maximal event count can be got at a time * Returns: Maximal event count can be got at a time
* (should be supported by the backend). * (should be supported by the backend).
*/ */
protected @property inout(uint) maxEvents() protected @property uint maxEvents()
inout const pure nothrow @safe @nogc const pure nothrow @safe @nogc
{ {
return 128U; return 128U;
} }

View File

@ -203,7 +203,7 @@ struct ReadBuffer(T = ubyte)
numberRead = fillBuffer(b[], b.free, 0, 10); numberRead = fillBuffer(b[], b.free, 0, 10);
b += numberRead; b += numberRead;
result = b[0..$]; result = b[0 .. $];
assert(result[0] == 0); assert(result[0] == 0);
assert(result[1] == 1); assert(result[1] == 1);
assert(result[9] == 9); assert(result[9] == 9);
@ -261,7 +261,6 @@ struct ReadBuffer(T = ubyte)
allocator.reallocate(buf, (cap + blockSize) * T.sizeof); allocator.reallocate(buf, (cap + blockSize) * T.sizeof);
buffer_ = cast(T[]) buf; buffer_ = cast(T[]) buf;
}(); }();
buffer_[cap .. $] = T.init;
} }
ring = length_; ring = length_;
return buffer_[length_ .. $]; return buffer_[length_ .. $];
@ -280,7 +279,7 @@ struct ReadBuffer(T = ubyte)
b += numberRead; b += numberRead;
assert(b.length == 10); assert(b.length == 10);
result = b[0..$]; result = b[0 .. $];
assert(result[0] == 0); assert(result[0] == 0);
assert(result[9] == 9); assert(result[9] == 9);
b.clear(); b.clear();
@ -337,33 +336,25 @@ struct WriteBuffer(T = ubyte)
* size = Initial buffer size and the size by which the buffer will * size = Initial buffer size and the size by which the buffer will
* grow. * grow.
* allocator = Allocator. * allocator = Allocator.
*
* Precondition: $(D_INLINECODE size > 0 && allocator !is null)
*/ */
this(in size_t size, shared Allocator allocator = defaultAllocator) @trusted this(in size_t size, shared Allocator allocator = defaultAllocator) @trusted
in in
{ {
assert(size > 0); assert(size > 0);
assert(allocator !is null);
} }
body body
{ {
blockSize = size; blockSize = size;
ring = size - 1; ring = size - 1;
this(allocator); allocator_ = allocator;
buffer_ = cast(T[]) allocator_.allocate(size * T.sizeof); buffer_ = cast(T[]) allocator_.allocate(size * T.sizeof);
} }
@disable this(); @disable this();
/// Ditto.
this(shared Allocator allocator)
in
{
assert(allocator !is null);
}
body
{
allocator_ = allocator;
}
/** /**
* Deallocates the internal buffer. * Deallocates the internal buffer.
*/ */