]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[CLEANUP] replace a few occurrences of (flags & X) && !(flags & Y)
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Jan 2009 11:18:24 +0000 (12:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Jan 2009 11:18:24 +0000 (12:18 +0100)
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.

src/session.c
src/stream_sock.c

index 3443c46b6ce69a5a469153d815b50b0774af2db4..aacde922250ad27c082f32d9536cd6edbe4beed3 100644 (file)
@@ -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);
index 59fc3e626ee85050ee54bbb3f1882a474409f904..3d0845ca4214426e3b8ee989247723b77c6c066f 100644 (file)
@@ -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: