Skip to content

Commit 3d250b3

Browse files
committed
MINOR: pattern: split pat_ref_set()
split pat_ref_set() function in 2 distinct functions. Indeed, since 0844bed ("MEDIUM: map/acl: Improve pat_ref_set() efficiency (for "set-map", "add-acl" action perfs)"), pat_ref_set() prototype was updated to include an extra <elt> argument. But the logic behind is not explicit because the function will not only try to set <elt>, but also its duplicate (unlike pat_ref_set_elt() which only tries to update <elt>). Thus, to make it clearer and better distinguish between the key-based lookup version and the elt-based one, restotre pat_ref_set() previous prototype and add a dedicated pat_ref_set_elt_duplicate() that takes <elt> as argument and tries to update <elt> and all duplicates.
1 parent 4d58f52 commit 3d250b3

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

include/haproxy/pattern.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ struct pat_ref_elt *pat_ref_append(struct pat_ref *ref, const char *pattern, con
188188
struct pat_ref_elt *pat_ref_load(struct pat_ref *ref, unsigned int gen, const char *pattern, const char *sample, int line, char **err);
189189
int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, int patflags, char **err);
190190
int pat_ref_add(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
191-
int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err, struct pat_ref_elt *elt);
191+
int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
192+
int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, char **err);
192193
int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const char *value, char **err);
193194
int pat_ref_delete(struct pat_ref *ref, const char *key);
194195
void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);

src/hlua.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2294,7 +2294,7 @@ static int hlua_set_map(lua_State *L)
22942294
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->lock);
22952295
elt = pat_ref_find_elt(ref, key);
22962296
if (elt)
2297-
pat_ref_set(ref, key, value, NULL, elt);
2297+
pat_ref_set_elt_duplicate(ref, elt, value, NULL);
22982298
else
22992299
pat_ref_add(ref, key, value, NULL);
23002300
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ref->lock);

src/http_act.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ static enum act_return http_action_set_map(struct act_rule *rule, struct proxy *
18481848
elt = pat_ref_find_elt(ref, key->area);
18491849
if (elt) {
18501850
/* update entry if it exists */
1851-
pat_ref_set(ref, key->area, value->area, NULL, elt);
1851+
pat_ref_set_elt_duplicate(ref, elt, value->area, NULL);
18521852
}
18531853
else {
18541854
/* insert a new entry */

src/map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx,
808808
*/
809809
err = NULL;
810810
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ctx->ref->lock);
811-
if (!pat_ref_set(ctx->ref, args[3], args[4], &err, NULL)) {
811+
if (!pat_ref_set(ctx->ref, args[3], args[4], &err)) {
812812
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ctx->ref->lock);
813813
if (err)
814814
return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));

src/pattern.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,21 +1754,10 @@ int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const cha
17541754
return 0;
17551755
}
17561756

1757-
/* This function modifies to <value> the sample of all patterns matching <key>
1758-
* under <ref>.
1759-
*/
1760-
int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err, struct pat_ref_elt *elt)
1757+
static int pat_ref_set_from_node(struct pat_ref *ref, struct ebmb_node *node, const char *value, char **err)
17611758
{
1759+
struct pat_ref_elt *elt;
17621760
int found = 0;
1763-
struct ebmb_node *node;
1764-
1765-
if (elt) {
1766-
node = &elt->node;
1767-
}
1768-
else {
1769-
/* Look for pattern in the reference. */
1770-
node = ebst_lookup(&ref->ebmb_root, key);
1771-
}
17721761

17731762
while (node) {
17741763
char *tmp_err = NULL;
@@ -1792,6 +1781,25 @@ int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **
17921781
return 1;
17931782
}
17941783

1784+
/* modifies to <value> the sample for <elt> and all its duplicates */
1785+
int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value,
1786+
char **err)
1787+
{
1788+
return pat_ref_set_from_node(ref, &elt->node, value, err);
1789+
}
1790+
1791+
/* This function modifies to <value> the sample of all patterns matching <key>
1792+
* under <ref>.
1793+
*/
1794+
int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err)
1795+
{
1796+
struct ebmb_node *node;
1797+
1798+
/* Look for pattern in the reference. */
1799+
node = ebst_lookup(&ref->ebmb_root, key);
1800+
return pat_ref_set_from_node(ref, node, value, err);
1801+
}
1802+
17951803
/* helper function to create and initialize a generic pat_ref struct
17961804
*
17971805
* Returns the new struct on success and NULL on failure (memory allocation

0 commit comments

Comments
 (0)