From 29930f0e427840065501c0728701028a99ddee26 Mon Sep 17 00:00:00 2001 From: shifter Date: Wed, 4 Dec 2024 16:50:01 +0100 Subject: [PATCH] filterx: regexp_subst auto-enable 'nogroups' when no match groups are 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 --- lib/filterx/expr-regexp-subst.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/filterx/expr-regexp-subst.c b/lib/filterx/expr-regexp-subst.c index 4dc1ad2ba..ba6d2bb95 100644 --- a/lib/filterx/expr-regexp-subst.c +++ b/lib/filterx/expr-regexp-subst.c @@ -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) { @@ -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;