From: Willy Tarreau Date: Sun, 15 Sep 2024 21:15:59 +0000 (+0200) Subject: MINOR: vars: remove the emptiness tests in callers before pruning X-Git-Tag: v3.1-dev8~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6e92988e20368e31587f68d297a0f7452c543274;p=thirdparty%2Fhaproxy.git MINOR: vars: remove the emptiness tests in callers before pruning 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. --- diff --git a/include/haproxy/vars.h b/include/haproxy/vars.h index 641fba2745..95bb4dcd80 100644 --- a/include/haproxy/vars.h +++ b/include/haproxy/vars.h @@ -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); } diff --git a/src/http_ana.c b/src/http_ana.c index a62d82cff5..5a95338b6c 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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); diff --git a/src/stream.c b/src/stream.c index 4e87aab541..550fd512e5 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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); } diff --git a/src/vars.c b/src/vars.c index f7d12e8484..0c34202e6f 100644 --- a/src/vars.c +++ b/src/vars.c @@ -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)