>From 66e1bb3dd77d17c3a393a5b053ab8d6141eaf6d3 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 18 Sep 2026 14:33:12 +0000 Subject: [PATCH 14/25] regex: optimize . in REG_NEWLINE with REG_NEWLINE . does not match \n, so in the ast it is represented as the union of literal(0,\n-1) and literal(\n+1,max) similarly to how [a-z0-9] is represented, except with . the two literals got separate position. this works but increases the number of transitions and the number of states tracked during exec. since . is common and can appear in iterated patterns like .{100} change it to be consistent with the more efficient bracket representation. --- src/regex/regcomp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c index 9aa5e23b..87662cfe 100644 --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -881,7 +881,7 @@ static reg_errcode_t parse_atom(tre_parse_ctx_t *ctx, const char *s) case '.': if (ctx->cflags & REG_NEWLINE) { tre_ast_node_t *tmp1, *tmp2; - tmp1 = tre_ast_new_literal(ctx->mem, 0, '\n'-1, ctx->position++); + tmp1 = tre_ast_new_literal(ctx->mem, 0, '\n'-1, ctx->position); tmp2 = tre_ast_new_literal(ctx->mem, '\n'+1, TRE_CHAR_MAX, ctx->position++); if (tmp1 && tmp2) node = tre_ast_new_union(ctx->mem, tmp1, tmp2); -- 2.52.0