From: Willy Tarreau Date: Fri, 9 Jan 2009 11:18:24 +0000 (+0100) Subject: [CLEANUP] replace a few occurrences of (flags & X) && !(flags & Y) X-Git-Tag: v1.3.16-rc1~78 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efc612c17b2320d09d26c36780faeb121ac66fe8;p=thirdparty%2Fhaproxy.git [CLEANUP] replace a few occurrences of (flags & X) && !(flags & Y) This construct collapses into ((flags & (X|Y)) == X) when X is a single-bit flag. This provides a noticeable code shrink and the output code results in less conditional jumps. --- diff --git a/src/session.c b/src/session.c index 3443c46b6c..aacde92225 100644 --- a/src/session.c +++ b/src/session.c @@ -184,7 +184,7 @@ int sess_update_st_con_tcp(struct session *s, struct stream_interface *si) if (unlikely((req->flags & BF_SHUTW_NOW) || (rep->flags & BF_SHUTW) || ((req->flags & BF_SHUTR) && /* FIXME: this should not prevent a connection from establishing */ - ((req->flags & BF_EMPTY && !(req->flags & BF_WRITE_ACTIVITY)) || + (((req->flags & (BF_EMPTY|BF_WRITE_ACTIVITY)) == BF_EMPTY) || s->be->options & PR_O_ABRT_CLOSE)))) { /* give up */ si->shutw(si); diff --git a/src/stream_sock.c b/src/stream_sock.c index 59fc3e626e..3d0845ca42 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -241,16 +241,17 @@ int stream_sock_read(int fd) { goto out_skip_wakeup; out_wakeup: /* the consumer might be waiting for data */ - if (b->cons->flags & SI_FL_WAIT_DATA && (b->flags & BF_READ_PARTIAL) && !(b->flags & BF_EMPTY)) + if (likely((b->flags & (BF_READ_PARTIAL|BF_EMPTY)) == BF_READ_PARTIAL && + (b->cons->flags & SI_FL_WAIT_DATA))) b->cons->chk_snd(b->cons); /* we have to wake up if there is a special event or if we don't have * any more data to forward. */ - if ((b->flags & (BF_READ_NULL|BF_READ_ERROR|BF_SHUTR)) || - !b->to_forward || - si->state != SI_ST_EST || - b->cons->state != SI_ST_EST) + if (likely((b->flags & (BF_READ_NULL|BF_READ_ERROR|BF_SHUTR)) || + !b->to_forward || + si->state != SI_ST_EST || + b->cons->state != SI_ST_EST)) task_wakeup(si->owner, TASK_WOKEN_IO); out_skip_wakeup: @@ -461,16 +462,17 @@ int stream_sock_write(int fd) { goto out_skip_wakeup; out_wakeup: /* the producer might be waiting for more room to store data */ - if ((b->prod->flags & SI_FL_WAIT_ROOM) && (b->flags & BF_WRITE_PARTIAL) && !(b->flags & BF_FULL)) + if (likely((b->flags & (BF_WRITE_PARTIAL|BF_FULL)) == BF_WRITE_PARTIAL && + (b->prod->flags & SI_FL_WAIT_ROOM))) b->prod->chk_rcv(b->prod); /* we have to wake up if there is a special event or if we don't have * any more data to forward and it's not planned to send any more. */ - if ((b->flags & (BF_WRITE_NULL|BF_WRITE_ERROR|BF_SHUTW)) || - (!b->to_forward && !b->send_max && !b->splice_len) || - si->state != SI_ST_EST || - b->prod->state != SI_ST_EST) + if (likely((b->flags & (BF_WRITE_NULL|BF_WRITE_ERROR|BF_SHUTW)) || + (!b->to_forward && !b->send_max && !b->splice_len) || + si->state != SI_ST_EST || + b->prod->state != SI_ST_EST)) task_wakeup(si->owner, TASK_WOKEN_IO); out_skip_wakeup: