]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: lua: limit usage of si_ic/si_oc
authorWilly Tarreau <w@1wt.eu>
Tue, 10 Mar 2015 11:03:52 +0000 (12:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 Mar 2015 19:41:47 +0000 (20:41 +0100)
As much as possible, we copy the result of this function into a local
variable to avoid having to check the flag all the time.

src/hlua.c

index d2ff34e43959ee0b4ab7902dd2e08c9a5eec6559..78f67731f58aa2756dedec6c35b8d240b0897ca0 100644 (file)
@@ -1216,6 +1216,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        char *blk2;
        int len2;
        int skip_at_end = 0;
+       struct channel *oc;
 
        /* Check if this lua stack is schedulable. */
        if (!hlua || !hlua->task)
@@ -1226,9 +1227,10 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        if (!socket->s)
                goto connection_closed;
 
+       oc = si_oc(&socket->s->si[0]);
        if (wanted == HLSR_READ_LINE) {
                /* Read line. */
-               nblk = bo_getline_nc(si_oc(&socket->s->si[0]), &blk1, &len1, &blk2, &len2);
+               nblk = bo_getline_nc(oc, &blk1, &len1, &blk2, &len2);
                if (nblk < 0) /* Connection close. */
                        goto connection_closed;
                if (nblk == 0) /* No data avalaible. */
@@ -1259,7 +1261,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
 
        else if (wanted == HLSR_READ_ALL) {
                /* Read all the available data. */
-               nblk = bo_getblk_nc(si_oc(&socket->s->si[0]), &blk1, &len1, &blk2, &len2);
+               nblk = bo_getblk_nc(oc, &blk1, &len1, &blk2, &len2);
                if (nblk < 0) /* Connection close. */
                        goto connection_closed;
                if (nblk == 0) /* No data avalaible. */
@@ -1268,7 +1270,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
 
        else {
                /* Read a block of data. */
-               nblk = bo_getblk_nc(si_oc(&socket->s->si[0]), &blk1, &len1, &blk2, &len2);
+               nblk = bo_getblk_nc(oc, &blk1, &len1, &blk2, &len2);
                if (nblk < 0) /* Connection close. */
                        goto connection_closed;
                if (nblk == 0) /* No data avalaible. */
@@ -1290,7 +1292,7 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
        }
 
        /* Consume data. */
-       bo_skip(si_oc(&socket->s->si[0]), len + skip_at_end);
+       bo_skip(oc, len + skip_at_end);
 
        /* Don't wait anything. */
        si_update(&socket->s->si[0]);
@@ -2844,16 +2846,20 @@ static int hlua_txn_new(lua_State *L, struct session *s, struct proxy *p, void *
 __LJMP static int hlua_txn_close(lua_State *L)
 {
        struct hlua_txn *s;
+       struct channel *ic, *oc;
 
        MAY_LJMP(check_args(L, 1, "close"));
        s = MAY_LJMP(hlua_checktxn(L, 1));
 
-       channel_abort(si_ic(&s->s->si[0]));
-       channel_auto_close(si_ic(&s->s->si[0]));
-       channel_erase(si_ic(&s->s->si[0]));
-       channel_auto_read(si_oc(&s->s->si[0]));
-       channel_auto_close(si_oc(&s->s->si[0]));
-       channel_shutr_now(si_oc(&s->s->si[0]));
+       ic = si_ic(&s->s->si[0]);
+       oc = si_oc(&s->s->si[0]);
+
+       channel_abort(ic);
+       channel_auto_close(ic);
+       channel_erase(ic);
+       channel_auto_read(oc);
+       channel_auto_close(oc);
+       channel_shutr_now(oc);
 
        return 0;
 }