From b2b072dd807c302eeb7ca987efe9ec06add156ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 22 Feb 2018 01:58:49 +0100 Subject: [PATCH] Reduce the number of ChoppedVector index operations. --- source/eventcore/drivers/posix/driver.d | 11 ++++++----- source/eventcore/drivers/posix/sockets.d | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/eventcore/drivers/posix/driver.d b/source/eventcore/drivers/posix/driver.d index 15e9e95..5dd4f0a 100644 --- a/source/eventcore/drivers/posix/driver.d +++ b/source/eventcore/drivers/posix/driver.d @@ -265,13 +265,14 @@ package class PosixEventLoop { package void clearFD(FD fd) { - if (m_fds[fd.value].common.userDataDestructor) - () @trusted { m_fds[fd.value].common.userDataDestructor(m_fds[fd.value].common.userData.ptr); } (); - if (!(m_fds[fd.value].common.flags & FDFlags.internal)) - foreach (cb; m_fds[fd.value].common.callback) + auto slot = () @trusted { return &m_fds[fd.value]; } (); + if (slot.common.userDataDestructor) + () @trusted { slot.common.userDataDestructor(slot.common.userData.ptr); } (); + if (!(slot.common.flags & FDFlags.internal)) + foreach (cb; slot.common.callback) if (cb !is null) m_waiterCount--; - m_fds[fd.value] = m_fds.FullField.init; + *slot = m_fds.FullField.init; } } diff --git a/source/eventcore/drivers/posix/sockets.d b/source/eventcore/drivers/posix/sockets.d index c3d4413..57abd22 100644 --- a/source/eventcore/drivers/posix/sockets.d +++ b/source/eventcore/drivers/posix/sockets.d @@ -803,10 +803,11 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets final override bool releaseRef(SocketFD fd) { import taggedalgebraic : hasType; - assert(m_loop.m_fds[fd].common.refCount > 0, "Releasing reference to unreferenced socket FD."); + auto slot = () @trusted { return &m_loop.m_fds[fd]; } (); + assert(slot.common.refCount > 0, "Releasing reference to unreferenced socket FD."); // listening sockets have an incremented the reference count because of setNotifyCallback - int base_refcount = m_loop.m_fds[fd].specific.hasType!StreamListenSocketSlot ? 1 : 0; - if (--m_loop.m_fds[fd].common.refCount == base_refcount) { + int base_refcount = slot.specific.hasType!StreamListenSocketSlot ? 1 : 0; + if (--slot.common.refCount == base_refcount) { m_loop.unregisterFD(fd, EventMask.read|EventMask.write|EventMask.status); m_loop.clearFD(fd); closeSocket(cast(sock_t)fd);