]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: vars: remove the emptiness tests in callers before pruning
authorWilly Tarreau <w@1wt.eu>
Sun, 15 Sep 2024 21:15:59 +0000 (23:15 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 15 Sep 2024 21:44:16 +0000 (23:44 +0200)
All callers of vars_prune_* currently check the list for emptiness.
Let's leave that to vars_prune() itself, it will ease some changes in
the code. Thanks to the previous inlining of the vars_prune() function,
there's no performance loss, and even a very tiny 0.1% gain.

include/haproxy/vars.h
src/http_ana.c
src/stream.c
src/vars.c

index 641fba2745f9b0fbe0f3d29333f467226b9c2658..95bb4dcd80c1db7b837c9ca3537bca05d0658c33 100644 (file)
@@ -85,6 +85,9 @@ static inline void vars_prune(struct vars *vars, struct session *sess, struct st
                size += var_clear(var, 1);
        }
 
+       if (!size)
+               return;
+
        var_accounting_diff(vars, sess, strm, -size);
 }
 
index a62d82cff50a3223fc489a253ac15955a271144f..5a95338b6cc8e5c5358baa29e293046437971a33 100644 (file)
@@ -2967,8 +2967,7 @@ int http_eval_after_res_rules(struct stream *s)
 
        /* prune the request variables if not already done and swap to the response variables. */
        if (s->vars_reqres.scope != SCOPE_RES) {
-               if (!LIST_ISEMPTY(&s->vars_reqres.head))
-                       vars_prune(&s->vars_reqres, s->sess, s);
+               vars_prune(&s->vars_reqres, s->sess, s);
                vars_init_head(&s->vars_reqres, SCOPE_RES);
        }
 
@@ -5094,10 +5093,8 @@ void http_destroy_txn(struct stream *s)
        txn->srv_cookie = NULL;
        txn->cli_cookie = NULL;
 
-       if (!LIST_ISEMPTY(&s->vars_txn.head))
-               vars_prune(&s->vars_txn, s->sess, s);
-       if (!LIST_ISEMPTY(&s->vars_reqres.head))
-               vars_prune(&s->vars_reqres, s->sess, s);
+       vars_prune(&s->vars_txn, s->sess, s);
+       vars_prune(&s->vars_reqres, s->sess, s);
 
        b_free(&txn->l7_buffer);
 
index 4e87aab54115a52a090a2a0642c38b3b9114bc0a..550fd512e55dcac1846b1de4d7c012618acd188d 100644 (file)
@@ -695,10 +695,8 @@ void stream_free(struct stream *s)
        }
 
        /* Cleanup all variable contexts. */
-       if (!LIST_ISEMPTY(&s->vars_txn.head))
-               vars_prune(&s->vars_txn, s->sess, s);
-       if (!LIST_ISEMPTY(&s->vars_reqres.head))
-               vars_prune(&s->vars_reqres, s->sess, s);
+       vars_prune(&s->vars_txn, s->sess, s);
+       vars_prune(&s->vars_reqres, s->sess, s);
 
        stream_store_counters(s);
        pool_free(pool_head_stk_ctr, s->stkctr);
@@ -2309,8 +2307,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
        if (sc_state_in(scb->state, SC_SB_REQ|SC_SB_QUE|SC_SB_TAR|SC_SB_ASS)) {
                /* prune the request variables and swap to the response variables. */
                if (s->vars_reqres.scope != SCOPE_RES) {
-                       if (!LIST_ISEMPTY(&s->vars_reqres.head))
-                               vars_prune(&s->vars_reqres, s->sess, s);
+                       vars_prune(&s->vars_reqres, s->sess, s);
                        vars_init_head(&s->vars_reqres, SCOPE_RES);
                }
 
index f7d12e84846cb8c99181df1749800c5efff4cf7b..0c34202e6fc06d9b7d955c8cc6635d0a5d19dd08 100644 (file)
@@ -207,6 +207,9 @@ void vars_prune_per_sess(struct vars *vars)
                size += var_clear(var, 1);
        }
 
+       if (!size)
+               return;
+
        if (var_sess_limit)
                _HA_ATOMIC_SUB(&vars->size, size);
        if (var_proc_limit || var_global_limit)