[glib/wip/3v1n0/regex-pcre2-flags-fixes: 11/11] regex: Avoid allocating offsets until we've a match




commit ae28f1382fd0332370eab266e38378b4cd66e7e1
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Sep 6 19:19:03 2022 +0200

    regex: Avoid allocating offsets until we've a match
    
    There's no much point of pre-allocating offsets given that we're doing
    this when needed if only have matches to store.
    
    So let's just allocate the spaces for the dummy offset we depend on,
    while allocate the others on demand.

 glib/gregex.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
---
diff --git a/glib/gregex.c b/glib/gregex.c
index 3a2c7a3860..de22547479 100644
--- a/glib/gregex.c
+++ b/glib/gregex.c
@@ -816,15 +816,11 @@ match_info_new (const GRegex     *regex,
     {
       /* These values should be enough for most cases, if they are not
        * enough g_regex_match_all_full() will expand them. */
-      match_info->n_offsets = 24;
       match_info->n_workspace = 100;
       match_info->workspace = g_new (gint, match_info->n_workspace);
     }
-  else
-    {
-      match_info->n_offsets = (match_info->n_subpatterns + 1) * 3;
-    }
 
+  match_info->n_offsets = 2;
   match_info->offsets = g_new0 (gint, match_info->n_offsets);
   /* Set an invalid position for the previous match. */
   match_info->offsets[0] = -1;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]