r16584@catbus: nickm | 2007-11-10 00:00:59 -0500
authorNick Mathewson <nickm@torproject.org>
Sat, 10 Nov 2007 05:18:11 +0000 (05:18 +0000)
committerNick Mathewson <nickm@torproject.org>
Sat, 10 Nov 2007 05:18:11 +0000 (05:18 +0000)
 Patch from Christopher Lane: reduce branch count in epoll_dispatch.c and generally improve clarity.

svn:r505

ChangeLog
epoll.c

index aea092a3815942854a1c8e08d77aed83f4978a06..f2b34b545d41feb1a0107022b2c8397cbaa907a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -35,7 +35,7 @@ Changes in current version:
  o added two additional libraries: libevent_core and libevent_extra in addition to the regular libevent.  libevent_core contains only the event core whereas libevent_extra contains dns, http and rpc support
  o Begin using libtool's library versioning support correctly.  If we don't mess up, this will more or less guarantee binaries linked against old versions of libevent continue working when we make changes to libevent that do not break backward compatibility.
  o Fix evhttp.h compilation when TAILQ_ENTRY is not defined.
- o Small code cleanups in epoll_dispatch().
+ o Clean up code in epoll_dispatch() to reduce branch count and generally run better.  Patch from Christopher Layne.
  o Increase the maximum number of addresses read from a packet in evdns to 32.
  o Remove support for the rtsig method: it hasn't compiled for a while, and nobody seems to miss it very much.  Let us know if there's a good reason to put it back in.
  o Rename the "class" field in evdns_server_request to dns_question_class, so that it won't break compilation under C++.  Use a macro so that old code won't break.  Mark the macro as deprecated.
diff --git a/epoll.c b/epoll.c
index 5afc83071e8562fcd22a084eba189beb1050c3b7..86a97a4c6602bfc28346e0a188a37965f82112ec 100644 (file)
--- a/epoll.c
+++ b/epoll.c
@@ -209,36 +209,23 @@ epoll_dispatch(struct event_base *base, void *arg, struct timeval *tv)
 
        for (i = 0; i < res; i++) {
                int what = events[i].events;
-               struct event *evread = NULL, *evwrite = NULL;
+               struct event *evread, *evwrite;
 
                evep = (struct evepoll *)events[i].data.ptr;
+               evread = evep->evread;
+               evwrite = evep->evwrite;
 
-               if (what & (EPOLLHUP|EPOLLERR)) {
-                       evread = evep->evread;
-                       evwrite = evep->evwrite;
-               } else {
-                       if (what & EPOLLIN) {
-                               evread = evep->evread;
-                       }
-
-                       if (what & EPOLLOUT) {
-                               evwrite = evep->evwrite;
-                       }
-               }
-
-               if (!(evread||evwrite))
-                       continue;
-
-               if (evread != NULL && !(evread->ev_events & EV_PERSIST))
-                       event_del(evread);
-               if (evwrite != NULL && evwrite != evread &&
-                       !(evwrite->ev_events & EV_PERSIST))
-                       event_del(evwrite);
-
-               if (evread != NULL)
+               if (evread && what & (EPOLLIN|EPOLLHUP|EPOLLERR)) {
+                       if (~evread->ev_events & EV_PERSIST)
+                               event_del(evread);
                        event_active(evread, EV_READ, 1);
-               if (evwrite != NULL)
+               }
+               if (evwrite && what & (EPOLLOUT|EPOLLHUP|EPOLLERR)) {
+                       if (~evwrite->ev_events & EV_PERSIST
+                               && evwrite != evread)
+                               event_del(evwrite);
                        event_active(evwrite, EV_WRITE, 1);
+               }
        }
 
        return (0);