[Libevent-users] [PATCH] epoll.c: epoll_dispatch() clarity/simplification/branch reduction cleanups

Christopher Layne clayne at anodized.com
Fri Nov 9 05:27:07 EST 2007


Regress checks out OK with both -O0 and -Os. Both size are with -O0.

$ size .libs/libevent-1.4.so.2
   text    data     bss     dec     hex filename
  93735    1088    7084  101907   18e13 .libs/libevent-1.4.so.2

$ size .libs/libevent-1.4.so.2
   text    data     bss     dec     hex filename
  93663    1088    7084  101835   18dcb .libs/libevent-1.4.so.2

Index: libevent/epoll.c
===================================================================
--- libevent/epoll.c	(revision 504)
+++ libevent/epoll.c	(working copy)
@@ -209,36 +209,23 @@
 
 	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);


More information about the Libevent-users mailing list