1From fe1c2628d52ca67ffe59420a0b4d371893795e62 Mon Sep 17 00:00:00 2001 2From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net> 3Date: Tue, 6 Sep 2022 19:19:03 +0200 4Subject: [PATCH] regex: Avoid allocating offsets until we've a match 5 6There's no much point of pre-allocating offsets given that we're doing 7this when needed if only have matches to store. 8 9So let's just allocate the spaces for the dummy offset we depend on, 10while allocate the others on demand. 11--- 12 glib/gregex.c | 6 +----- 13 1 file changed, 1 insertion(+), 5 deletions(-) 14 15diff --git a/glib/gregex.c b/glib/gregex.c 16index 8a3be9076b..7d403ad53d 100644 17--- a/glib/gregex.c 18+++ b/glib/gregex.c 19@@ -806,15 +806,11 @@ match_info_new (const GRegex *regex, 20 { 21 /* These values should be enough for most cases, if they are not 22 * enough g_regex_match_all_full() will expand them. */ 23- match_info->n_offsets = 24; 24 match_info->n_workspace = 100; 25 match_info->workspace = g_new (gint, match_info->n_workspace); 26 } 27- else 28- { 29- match_info->n_offsets = (match_info->n_subpatterns + 1) * 3; 30- } 31 32+ match_info->n_offsets = 2; 33 match_info->offsets = g_new0 (gint, match_info->n_offsets); 34 /* Set an invalid position for the previous match. */ 35 match_info->offsets[0] = -1; 36-- 37GitLab 38 39