Reduce the number of ChoppedVector index operations.

This commit is contained in:
Sönke Ludwig 2018-02-22 01:58:49 +01:00
parent 30f614a7ff
commit b2b072dd80
2 changed files with 10 additions and 8 deletions

View file

@ -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;
}
}

View file

@ -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);