summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2016-12-25 00:54:05 +0100
committerEugen Wissner <belka@caraus.de>2016-12-25 00:54:05 +0100
commit0156c5a8834bc83b2af74adeae1b3357ead90cf2 (patch)
tree99ac738256b41e2cb58c211090046b8736945e25
parentc966b42ac310488cb1c4174e0dbe4013c0af9bf5 (diff)
downloadtanya-0156c5a8834bc83b2af74adeae1b3357ead90cf2.tar.gz
Don't allocate watcher queue on the heap
-rw-r--r--source/tanya/async/loop.d5
-rw-r--r--source/tanya/async/watcher.d12
-rw-r--r--source/tanya/container/buffer.d2
3 files changed, 9 insertions, 10 deletions
diff --git a/source/tanya/async/loop.d b/source/tanya/async/loop.d
index 1526251..f904243 100644
--- a/source/tanya/async/loop.d
+++ b/source/tanya/async/loop.d
@@ -133,6 +133,7 @@ abstract class Loop
/// Pending watchers.
protected Queue!Watcher* pendings;
+ /// Ditto.
protected Queue!Watcher* swapPendings;
/**
@@ -150,8 +151,8 @@ abstract class Loop
*/
this() @nogc
{
- pendings = MmapPool.instance.make!(Queue!Watcher);
- swapPendings = MmapPool.instance.make!(Queue!Watcher);
+ pendings = MmapPool.instance.make!(Queue!Watcher)(MmapPool.instance);
+ swapPendings = MmapPool.instance.make!(Queue!Watcher)(MmapPool.instance);
}
/**
diff --git a/source/tanya/async/watcher.d b/source/tanya/async/watcher.d
index f6915ab..2bbccad 100644
--- a/source/tanya/async/watcher.d
+++ b/source/tanya/async/watcher.d
@@ -53,7 +53,7 @@ class ConnectionWatcher : Watcher
/// Protocol factory.
protected Protocol delegate() @nogc protocolFactory;
- package Queue!IOWatcher* incoming;
+ package Queue!IOWatcher incoming;
/**
* Params:
@@ -62,7 +62,6 @@ class ConnectionWatcher : Watcher
this(Socket socket) @nogc
{
socket_ = socket;
- incoming = MmapPool.instance.make!(Queue!IOWatcher);
}
/// Ditto.
@@ -72,14 +71,13 @@ class ConnectionWatcher : Watcher
~this() @nogc
{
- foreach (w; *incoming)
+ foreach (w; incoming)
{
MmapPool.instance.dispose(w);
}
- MmapPool.instance.dispose(incoming);
}
- /*
+ /**
* Params:
* P = Protocol should be used.
*/
@@ -114,7 +112,7 @@ class ConnectionWatcher : Watcher
*/
override void invoke() @nogc
{
- foreach (io; *incoming)
+ foreach (io; incoming)
{
io.protocol.connected(cast(DuplexTransport) io.transport);
}
@@ -164,7 +162,7 @@ class IOWatcher : ConnectionWatcher
/**
* Destroys the watcher.
*/
- protected ~this() @nogc
+ ~this() @nogc
{
MmapPool.instance.dispose(protocol_);
}
diff --git a/source/tanya/container/buffer.d b/source/tanya/container/buffer.d
index 18501f0..3854606 100644
--- a/source/tanya/container/buffer.d
+++ b/source/tanya/container/buffer.d
@@ -90,7 +90,7 @@ struct ReadBuffer(T = ubyte)
in size_t minAvailable = 1024,
shared Allocator allocator = defaultAllocator) @trusted
{
- this(allocator_);
+ this(allocator);
this.minAvailable = minAvailable;
this.blockSize = size;
buffer_ = cast(T[]) allocator_.allocate(size * T.sizeof);