Avoid unnecessary dictionary lookups in SocketEvents::ThreadProc

refs #11014
This commit is contained in:
Gunnar Beutner 2016-01-28 13:07:09 +01:00
parent d474877add
commit 211fc5ad53
1 changed files with 8 additions and 10 deletions

View File

@ -81,6 +81,7 @@ void SocketEvents::ThreadProc(void)
Utility::SetThreadName("SocketIO"); Utility::SetThreadName("SocketIO");
pollfd *pfds = NULL; pollfd *pfds = NULL;
SocketEventDescriptor *descriptors = NULL;
int pfdcount; int pfdcount;
for (;;) { for (;;) {
@ -88,17 +89,19 @@ void SocketEvents::ThreadProc(void)
boost::mutex::scoped_lock lock(l_SocketIOMutex); boost::mutex::scoped_lock lock(l_SocketIOMutex);
if (pfds == NULL) { if (pfds == NULL) {
typedef std::map<SOCKET, SocketEventDescriptor>::value_type SocketDesc;
pfdcount = l_SocketIOSockets.size(); pfdcount = l_SocketIOSockets.size();
pfds = new pollfd[pfdcount]; pfds = new pollfd[pfdcount];
descriptors = new SocketEventDescriptor[pfdcount];
int i = 0; int i = 0;
BOOST_FOREACH(const SocketDesc& desc, l_SocketIOSockets) { typedef std::map<SOCKET, SocketEventDescriptor>::value_type kv_pair;
BOOST_FOREACH(const kv_pair& desc, l_SocketIOSockets) {
pfds[i].fd = desc.first; pfds[i].fd = desc.first;
pfds[i].events = desc.second.Events; pfds[i].events = desc.second.Events;
pfds[i].revents = 0; pfds[i].revents = 0;
descriptors[i] = desc.second;
i++; i++;
} }
@ -121,6 +124,7 @@ void SocketEvents::ThreadProc(void)
if (l_SocketIOFDChanged) { if (l_SocketIOFDChanged) {
delete [] pfds; delete [] pfds;
delete [] descriptors;
pfds = NULL; pfds = NULL;
continue; continue;
} }
@ -139,13 +143,7 @@ void SocketEvents::ThreadProc(void)
EventDescription event; EventDescription event;
event.REvents = pfds[i].revents; event.REvents = pfds[i].revents;
event.Descriptor = descriptors[i];
std::map<SOCKET, SocketEventDescriptor>::const_iterator it = l_SocketIOSockets.find(pfds[i].fd);
if (it == l_SocketIOSockets.end())
continue;
event.Descriptor = it->second;
event.LifesupportReference = event.Descriptor.LifesupportObject; event.LifesupportReference = event.Descriptor.LifesupportObject;
VERIFY(event.LifesupportReference); VERIFY(event.LifesupportReference);