Skip to content

Commit 6e92988

Browse files
committed
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.
1 parent 2c1a9c3 commit 6e92988

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

include/haproxy/vars.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ static inline void vars_prune(struct vars *vars, struct session *sess, struct st
8585
size += var_clear(var, 1);
8686
}
8787

88+
if (!size)
89+
return;
90+
8891
var_accounting_diff(vars, sess, strm, -size);
8992
}
9093

src/http_ana.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,8 +2967,7 @@ int http_eval_after_res_rules(struct stream *s)
29672967

29682968
/* prune the request variables if not already done and swap to the response variables. */
29692969
if (s->vars_reqres.scope != SCOPE_RES) {
2970-
if (!LIST_ISEMPTY(&s->vars_reqres.head))
2971-
vars_prune(&s->vars_reqres, s->sess, s);
2970+
vars_prune(&s->vars_reqres, s->sess, s);
29722971
vars_init_head(&s->vars_reqres, SCOPE_RES);
29732972
}
29742973

@@ -5094,10 +5093,8 @@ void http_destroy_txn(struct stream *s)
50945093
txn->srv_cookie = NULL;
50955094
txn->cli_cookie = NULL;
50965095

5097-
if (!LIST_ISEMPTY(&s->vars_txn.head))
5098-
vars_prune(&s->vars_txn, s->sess, s);
5099-
if (!LIST_ISEMPTY(&s->vars_reqres.head))
5100-
vars_prune(&s->vars_reqres, s->sess, s);
5096+
vars_prune(&s->vars_txn, s->sess, s);
5097+
vars_prune(&s->vars_reqres, s->sess, s);
51015098

51025099
b_free(&txn->l7_buffer);
51035100

src/stream.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,8 @@ void stream_free(struct stream *s)
695695
}
696696

697697
/* Cleanup all variable contexts. */
698-
if (!LIST_ISEMPTY(&s->vars_txn.head))
699-
vars_prune(&s->vars_txn, s->sess, s);
700-
if (!LIST_ISEMPTY(&s->vars_reqres.head))
701-
vars_prune(&s->vars_reqres, s->sess, s);
698+
vars_prune(&s->vars_txn, s->sess, s);
699+
vars_prune(&s->vars_reqres, s->sess, s);
702700

703701
stream_store_counters(s);
704702
pool_free(pool_head_stk_ctr, s->stkctr);
@@ -2309,8 +2307,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
23092307
if (sc_state_in(scb->state, SC_SB_REQ|SC_SB_QUE|SC_SB_TAR|SC_SB_ASS)) {
23102308
/* prune the request variables and swap to the response variables. */
23112309
if (s->vars_reqres.scope != SCOPE_RES) {
2312-
if (!LIST_ISEMPTY(&s->vars_reqres.head))
2313-
vars_prune(&s->vars_reqres, s->sess, s);
2310+
vars_prune(&s->vars_reqres, s->sess, s);
23142311
vars_init_head(&s->vars_reqres, SCOPE_RES);
23152312
}
23162313

src/vars.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ void vars_prune_per_sess(struct vars *vars)
207207
size += var_clear(var, 1);
208208
}
209209

210+
if (!size)
211+
return;
212+
210213
if (var_sess_limit)
211214
_HA_ATOMIC_SUB(&vars->size, size);
212215
if (var_proc_limit || var_global_limit)

0 commit comments

Comments
 (0)