]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: vars: use the item API for the variables trees
authorWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 08:47:52 +0000 (10:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 16 Sep 2025 08:51:23 +0000 (10:51 +0200)
The variables trees use the immediate cebtree API, better use the
item one which is more expressive and safer. The "node" field was
renamed to "name_node" to avoid any ambiguity.

include/haproxy/vars-t.h
include/haproxy/vars.h
src/vars.c

index 1575765855dc7373f49ae21001afa6263a7ca46d..105506977c0e1e6ea040a9a159bbc46495bf308b 100644 (file)
@@ -66,8 +66,8 @@ struct var_desc {
 };
 
 struct var {
-       struct ceb_node node; /* Used for chaining vars. */
-       uint64_t name_hash;      /* XXH3() of the variable's name, must be just after node */
+       struct ceb_node name_node; /* indexes <name_hash> below */
+       uint64_t name_hash;        /* XXH3() of the variable's name, indexed by <name_node> */
        uint flags;       // VF_*
        /* 32-bit hole here */
        struct sample_data data; /* data storage. */
index bffeb2214aa6e6b08fe3ff493ec36dd2ee678029..09d1e3b15fd7fa11aa15d99dde409736b7aa1b8e 100644 (file)
@@ -80,16 +80,13 @@ static inline void vars_rdunlock(struct vars *vars)
  */
 static inline void vars_prune(struct vars *vars, struct session *sess, struct stream *strm)
 {
-       struct ceb_node *node;
        struct var *var;
        unsigned int size = 0;
        int i;
 
        for (i = 0; i < VAR_NAME_ROOTS; i++) {
-               while ((node = cebu64_imm_first(&vars->name_root[i]))) {
-                       var = container_of(node, struct var, node);
+               while ((var = cebu64_item_first(&vars->name_root[i], name_node, name_hash, struct var)))
                        size += var_clear(vars, var, 1);
-               }
        }
 
        if (!size)
index 8e7ac8239e047011a0cb99b869d4eb696859cb17..878ad1a5e5f341e2c74b5dead5fca686150b9907 100644 (file)
@@ -190,7 +190,8 @@ unsigned int var_clear(struct vars *vars, struct var *var, int force)
        var->data.type = SMP_T_ANY;
 
        if (!(var->flags & VF_PERMANENT) || force) {
-               cebu64_imm_delete(&vars->name_root[var->name_hash % VAR_NAME_ROOTS], &var->node);
+               cebu64_item_delete(&vars->name_root[var->name_hash % VAR_NAME_ROOTS],
+                                  name_node, name_hash, var);
                pool_free(var_pool, var);
                size += sizeof(struct var);
        }
@@ -202,16 +203,13 @@ unsigned int var_clear(struct vars *vars, struct var *var, int force)
  */
 void vars_prune_per_sess(struct vars *vars)
 {
-       struct ceb_node *node;
        struct var *var;
        unsigned int size = 0;
        int i;
 
        for (i = 0; i < VAR_NAME_ROOTS; i++) {
-               while ((node = cebu64_imm_first(&vars->name_root[i]))) {
-                       var = container_of(node, struct var, node);
+               while ((var = cebu64_item_first(&vars->name_root[i], name_node, name_hash, struct var)))
                        size += var_clear(vars, var, 1);
-               }
        }
 
        if (!size)
@@ -334,13 +332,8 @@ static int vars_fill_desc(const char *name, int len, struct var_desc *desc, char
  */
 static struct var *var_get(struct vars *vars, uint64_t name_hash)
 {
-       struct ceb_node *node;
-
-       node = cebu64_imm_lookup(&vars->name_root[name_hash % VAR_NAME_ROOTS], name_hash);
-       if (node)
-               return container_of(node, struct var, node);
-
-       return NULL;
+       return cebu64_item_lookup(&vars->name_root[name_hash % VAR_NAME_ROOTS],
+                                 name_node, name_hash, name_hash, struct var);
 }
 
 /* Returns 0 if fails, else returns 1. */
@@ -439,7 +432,7 @@ int var_set(const struct var_desc *desc, struct sample *smp, uint flags)
                var->name_hash = desc->name_hash;
                var->flags = flags & VF_PERMANENT;
                var->data.type = SMP_T_ANY;
-               cebu64_imm_insert(&vars->name_root[var->name_hash % VAR_NAME_ROOTS], &var->node);
+               cebu64_item_insert(&vars->name_root[var->name_hash % VAR_NAME_ROOTS], name_node, name_hash, var);
        }
 
        /* A variable of type SMP_T_ANY is considered as unset (either created