Skip to content

Commit

Permalink
filterx: regexp_subst auto-enable 'nogroups' when no match groups are…
Browse files Browse the repository at this point in the history
… present

The function now automatically checks the replacement pattern at config
parsing time. If no match group references are found in the pattern, it
will behave as if the 'nogroups' option is enabled, disabling match group
functionality for performance reasons.

Signed-off-by: shifter <[email protected]>
  • Loading branch information
bshifter committed Dec 12, 2024
1 parent fd06ee7 commit 29930f0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/filterx/expr-regexp-subst.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ _extract_optional_flags(FilterXFuncRegexpSubst *self, FilterXFunctionArgs *args,
return TRUE;
}

static gboolean
_contains_match_grp_ref(gchar *str)
{
gchar *close = NULL;
return _next_matchgrp_ref(str, &close) != NULL;
}

static gboolean
_extract_subst_args(FilterXFuncRegexpSubst *self, FilterXFunctionArgs *args, GError **error)
{
Expand Down Expand Up @@ -366,7 +373,8 @@ filterx_function_regexp_subst_new(FilterXFunctionArgs *args, GError **error)
self->super.super.deinit = _subst_deinit;
self->super.super.free_fn = _subst_free;

reset_flags(&self->flags, FLAG_VAL(FILTERX_FUNC_REGEXP_SUBST_FLAG_JIT));
reset_flags(&self->flags, FLAG_VAL(FILTERX_FUNC_REGEXP_SUBST_FLAG_JIT) | FLAG_VAL(
FILTERX_FUNC_REGEXP_SUBST_FLAG_GROUPS));
if (!_extract_subst_args(self, args, error) ||
!filterx_function_args_check(args, error))
goto error;
Expand Down

0 comments on commit 29930f0

Please sign in to comment.