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