1From aee84cb45caf42e336dee5183d561b89eb44f8f3 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 18:56:39 +0200 4Subject: [PATCH] gregex: Avoid re-allocating if we have no size change 5 6This is handled by the syscall underneath, but we can just avoid a call 7cheaply. 8--- 9 glib/gregex.c | 13 ++++++++++--- 10 1 file changed, 10 insertions(+), 3 deletions(-) 11 12diff --git a/glib/gregex.c b/glib/gregex.c 13index 84c4245753..cf86f0fe0d 100644 14--- a/glib/gregex.c 15+++ b/glib/gregex.c 16@@ -832,6 +832,7 @@ recalc_match_offsets (GMatchInfo *match_info, 17 GError **error) 18 { 19 PCRE2_SIZE *ovector; 20+ uint32_t pre_n_offset; 21 uint32_t i; 22 23 if (pcre2_get_ovector_count (match_info->match_data) > G_MAXUINT32 / 2) 24@@ -842,11 +843,17 @@ recalc_match_offsets (GMatchInfo *match_info, 25 return FALSE; 26 } 27 28+ pre_n_offset = match_info->n_offsets; 29 match_info->n_offsets = pcre2_get_ovector_count (match_info->match_data) * 2; 30 ovector = pcre2_get_ovector_pointer (match_info->match_data); 31- match_info->offsets = g_realloc_n (match_info->offsets, 32- match_info->n_offsets, 33- sizeof (gint)); 34+ 35+ if (match_info->n_offsets != pre_n_offset) 36+ { 37+ match_info->offsets = g_realloc_n (match_info->offsets, 38+ match_info->n_offsets, 39+ sizeof (gint)); 40+ } 41+ 42 for (i = 0; i < match_info->n_offsets; i++) 43 { 44 match_info->offsets[i] = (int) ovector[i]; 45-- 46GitLab 47 48