1b5975d6bSopenharmony_ciFrom bcd8cb3e142bf7f1c92583aa81c34fe8ff8521c0 Mon Sep 17 00:00:00 2001
2b5975d6bSopenharmony_ciFrom: Aleksei Rybalkin <aleksei@rybalkin.org>
3b5975d6bSopenharmony_ciDate: Wed, 20 Jul 2022 20:48:17 +0000
4b5975d6bSopenharmony_ciSubject: [PATCH] gregex: use G_REGEX_OPTIMIZE flag to enable JIT compilation
5b5975d6bSopenharmony_ci
6b5975d6bSopenharmony_ciSince we ported gregex to pcre2, the JIT compiler is now available to be
7b5975d6bSopenharmony_ciused. Let's undeprecate G_REGEX_OPTIMIZE flag to control whether the JIT
8b5975d6bSopenharmony_cicompilation is requested, since using JIT is itself an optimization.
9b5975d6bSopenharmony_ciSee [1] for details on its implementation in pcre2.
10b5975d6bSopenharmony_ci
11b5975d6bSopenharmony_ci[1] http://pcre.org/current/doc/html/pcre2jit.html
12b5975d6bSopenharmony_ci
13b5975d6bSopenharmony_ciFixes: #566
14b5975d6bSopenharmony_ci
15b5975d6bSopenharmony_ciConflict:NA
16b5975d6bSopenharmony_ciReference:https://gitlab.gnome.org/GNOME/glib/-/commit/bcd8cb3e142bf7f1c92583aa81c34fe8ff8521c0
17b5975d6bSopenharmony_ci
18b5975d6bSopenharmony_ci---
19b5975d6bSopenharmony_ci glib/gregex.c      | 104 ++++++++++++++++++++++++++++++------
20b5975d6bSopenharmony_ci glib/gregex.h      |  14 ++---
21b5975d6bSopenharmony_ci glib/tests/regex.c | 128 ++++++++++++++++++++++++---------------------
22b5975d6bSopenharmony_ci 3 files changed, 164 insertions(+), 82 deletions(-)
23b5975d6bSopenharmony_ci
24b5975d6bSopenharmony_cidiff --git a/glib/gregex.c b/glib/gregex.c
25b5975d6bSopenharmony_ciindex b0edacc0d3..cf9ce23e8d 100644
26b5975d6bSopenharmony_ci--- a/glib/gregex.c
27b5975d6bSopenharmony_ci+++ b/glib/gregex.c
28b5975d6bSopenharmony_ci@@ -144,7 +144,6 @@
29b5975d6bSopenharmony_ci                             PCRE2_NOTBOL |           \
30b5975d6bSopenharmony_ci                             PCRE2_NOTEOL |           \
31b5975d6bSopenharmony_ci                             PCRE2_NOTEMPTY |         \
32b5975d6bSopenharmony_ci-                            PCRE2_PARTIAL_SOFT |     \
33b5975d6bSopenharmony_ci                             PCRE2_NEWLINE_CR |       \
34b5975d6bSopenharmony_ci                             PCRE2_NEWLINE_LF |       \
35b5975d6bSopenharmony_ci                             PCRE2_NEWLINE_CRLF |     \
36b5975d6bSopenharmony_ci@@ -195,6 +194,13 @@ struct _GMatchInfo
37b5975d6bSopenharmony_ci   pcre2_match_data *match_data;
38b5975d6bSopenharmony_ci };
39b5975d6bSopenharmony_ci 
40b5975d6bSopenharmony_ci+typedef enum
41b5975d6bSopenharmony_ci+{
42b5975d6bSopenharmony_ci+  JIT_STATUS_DEFAULT,
43b5975d6bSopenharmony_ci+  JIT_STATUS_ENABLED,
44b5975d6bSopenharmony_ci+  JIT_STATUS_DISABLED
45b5975d6bSopenharmony_ci+} JITStatus;
46b5975d6bSopenharmony_ci+
47b5975d6bSopenharmony_ci struct _GRegex
48b5975d6bSopenharmony_ci {
49b5975d6bSopenharmony_ci   gint ref_count;               /* the ref count for the immutable part (atomic) */
50b5975d6bSopenharmony_ci@@ -203,6 +209,8 @@ struct _GRegex
51b5975d6bSopenharmony_ci   GRegexCompileFlags compile_opts;      /* options used at compile time on the pattern, pcre2 values */
52b5975d6bSopenharmony_ci   GRegexCompileFlags orig_compile_opts; /* options used at compile time on the pattern, gregex values */
53b5975d6bSopenharmony_ci   GRegexMatchFlags match_opts;  /* options used at match time on the regex */
54b5975d6bSopenharmony_ci+  gint jit_options;             /* options which were enabled for jit compiler */
55b5975d6bSopenharmony_ci+  JITStatus jit_status;         /* indicates the status of jit compiler for this compiled regex */
56b5975d6bSopenharmony_ci };
57b5975d6bSopenharmony_ci 
58b5975d6bSopenharmony_ci /* TRUE if ret is an error code, FALSE otherwise. */
59b5975d6bSopenharmony_ci@@ -262,10 +270,11 @@ map_to_pcre2_compile_flags (gint pcre1_flags)
60b5975d6bSopenharmony_ci   if (pcre1_flags & G_REGEX_BSR_ANYCRLF)
61b5975d6bSopenharmony_ci     pcre2_flags |= PCRE2_BSR_ANYCRLF;
62b5975d6bSopenharmony_ci 
63b5975d6bSopenharmony_ci-  /* these are not available in pcre2 */
64b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
65b5975d6bSopenharmony_ci+  /* these are not available in pcre2, but we use G_REGEX_OPTIMIZE as a special
66b5975d6bSopenharmony_ci+   * case to request JIT compilation */
67b5975d6bSopenharmony_ci   if (pcre1_flags & G_REGEX_OPTIMIZE)
68b5975d6bSopenharmony_ci     pcre2_flags |= 0;
69b5975d6bSopenharmony_ci+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
70b5975d6bSopenharmony_ci   if (pcre1_flags & G_REGEX_JAVASCRIPT_COMPAT)
71b5975d6bSopenharmony_ci     pcre2_flags |= 0;
72b5975d6bSopenharmony_ci G_GNUC_END_IGNORE_DEPRECATIONS
73b5975d6bSopenharmony_ci@@ -291,8 +300,6 @@ map_to_pcre2_match_flags (gint pcre1_flags)
74b5975d6bSopenharmony_ci     pcre2_flags |= PCRE2_NOTEOL;
75b5975d6bSopenharmony_ci   if (pcre1_flags & G_REGEX_MATCH_NOTEMPTY)
76b5975d6bSopenharmony_ci     pcre2_flags |= PCRE2_NOTEMPTY;
77b5975d6bSopenharmony_ci-  if (pcre1_flags & G_REGEX_MATCH_PARTIAL)
78b5975d6bSopenharmony_ci-    pcre2_flags |= PCRE2_PARTIAL_SOFT;
79b5975d6bSopenharmony_ci   if (pcre1_flags & G_REGEX_MATCH_NEWLINE_CR)
80b5975d6bSopenharmony_ci     pcre2_flags |= PCRE2_NEWLINE_CR;
81b5975d6bSopenharmony_ci   if (pcre1_flags & G_REGEX_MATCH_NEWLINE_LF)
82b5975d6bSopenharmony_ci@@ -385,8 +392,6 @@ map_to_pcre1_match_flags (gint pcre2_flags)
83b5975d6bSopenharmony_ci     pcre1_flags |= G_REGEX_MATCH_NOTEOL;
84b5975d6bSopenharmony_ci   if (pcre2_flags & PCRE2_NOTEMPTY)
85b5975d6bSopenharmony_ci     pcre1_flags |= G_REGEX_MATCH_NOTEMPTY;
86b5975d6bSopenharmony_ci-  if (pcre2_flags & PCRE2_PARTIAL_SOFT)
87b5975d6bSopenharmony_ci-    pcre1_flags |= G_REGEX_MATCH_PARTIAL;
88b5975d6bSopenharmony_ci   if (pcre2_flags & PCRE2_NEWLINE_CR)
89b5975d6bSopenharmony_ci     pcre1_flags |= G_REGEX_MATCH_NEWLINE_CR;
90b5975d6bSopenharmony_ci   if (pcre2_flags & PCRE2_NEWLINE_LF)
91b5975d6bSopenharmony_ci@@ -461,6 +466,9 @@ match_error (gint errcode)
92b5975d6bSopenharmony_ci       return _("bad offset");
93b5975d6bSopenharmony_ci     case PCRE2_ERROR_RECURSELOOP:
94b5975d6bSopenharmony_ci       return _("recursion loop");
95b5975d6bSopenharmony_ci+    case PCRE2_ERROR_JIT_BADOPTION:
96b5975d6bSopenharmony_ci+      /* should not happen in GRegex since we check modes before each match */
97b5975d6bSopenharmony_ci+      return _("matching mode is requested that was not compiled for JIT");
98b5975d6bSopenharmony_ci     default:
99b5975d6bSopenharmony_ci       break;
100b5975d6bSopenharmony_ci     }
101b5975d6bSopenharmony_ci@@ -817,6 +825,56 @@ recalc_match_offsets (GMatchInfo *match_info,
102b5975d6bSopenharmony_ci   return TRUE;
103b5975d6bSopenharmony_ci }
104b5975d6bSopenharmony_ci 
105b5975d6bSopenharmony_ci+static void
106b5975d6bSopenharmony_ci+enable_jit_with_match_options (GRegex *regex,
107b5975d6bSopenharmony_ci+                               GRegexMatchFlags match_options)
108b5975d6bSopenharmony_ci+{
109b5975d6bSopenharmony_ci+  gint old_jit_options, new_jit_options, retval;
110b5975d6bSopenharmony_ci+
111b5975d6bSopenharmony_ci+  if (!(regex->orig_compile_opts & G_REGEX_OPTIMIZE))
112b5975d6bSopenharmony_ci+    return;
113b5975d6bSopenharmony_ci+  if (regex->jit_status == JIT_STATUS_DISABLED)
114b5975d6bSopenharmony_ci+    return;
115b5975d6bSopenharmony_ci+
116b5975d6bSopenharmony_ci+  old_jit_options = regex->jit_options;
117b5975d6bSopenharmony_ci+  new_jit_options = old_jit_options | PCRE2_JIT_COMPLETE;
118b5975d6bSopenharmony_ci+  if (match_options & PCRE2_PARTIAL_HARD)
119b5975d6bSopenharmony_ci+    new_jit_options |= PCRE2_JIT_PARTIAL_HARD;
120b5975d6bSopenharmony_ci+  if (match_options & PCRE2_PARTIAL_SOFT)
121b5975d6bSopenharmony_ci+    new_jit_options |= PCRE2_JIT_PARTIAL_SOFT;
122b5975d6bSopenharmony_ci+
123b5975d6bSopenharmony_ci+  /* no new options enabled */
124b5975d6bSopenharmony_ci+  if (new_jit_options == old_jit_options)
125b5975d6bSopenharmony_ci+    return;
126b5975d6bSopenharmony_ci+
127b5975d6bSopenharmony_ci+  retval = pcre2_jit_compile (regex->pcre_re, new_jit_options);
128b5975d6bSopenharmony_ci+  switch (retval)
129b5975d6bSopenharmony_ci+    {
130b5975d6bSopenharmony_ci+    case 0: /* JIT enabled successfully */
131b5975d6bSopenharmony_ci+      regex->jit_status = JIT_STATUS_ENABLED;
132b5975d6bSopenharmony_ci+      regex->jit_options = new_jit_options;
133b5975d6bSopenharmony_ci+      break;
134b5975d6bSopenharmony_ci+    case PCRE2_ERROR_NOMEMORY:
135b5975d6bSopenharmony_ci+      g_warning ("JIT compilation was requested with G_REGEX_OPTIMIZE, "
136b5975d6bSopenharmony_ci+                 "but JIT was unable to allocate executable memory for the "
137b5975d6bSopenharmony_ci+                 "compiler. Falling back to interpretive code.");
138b5975d6bSopenharmony_ci+      regex->jit_status = JIT_STATUS_DISABLED;
139b5975d6bSopenharmony_ci+      break;
140b5975d6bSopenharmony_ci+    case PCRE2_ERROR_JIT_BADOPTION:
141b5975d6bSopenharmony_ci+      g_warning ("JIT compilation was requested with G_REGEX_OPTIMIZE, "
142b5975d6bSopenharmony_ci+                 "but JIT support is not available. Falling back to "
143b5975d6bSopenharmony_ci+                 "interpretive code.");
144b5975d6bSopenharmony_ci+      regex->jit_status = JIT_STATUS_DISABLED;
145b5975d6bSopenharmony_ci+      break;
146b5975d6bSopenharmony_ci+    default:
147b5975d6bSopenharmony_ci+      g_warning ("JIT compilation was requested with G_REGEX_OPTIMIZE, "
148b5975d6bSopenharmony_ci+                 "but request for JIT support had unexpectedly failed. "
149b5975d6bSopenharmony_ci+                 "Falling back to interpretive code.");
150b5975d6bSopenharmony_ci+      regex->jit_status = JIT_STATUS_DISABLED;
151b5975d6bSopenharmony_ci+      break;
152b5975d6bSopenharmony_ci+    }
153b5975d6bSopenharmony_ci+}
154b5975d6bSopenharmony_ci+
155b5975d6bSopenharmony_ci /**
156b5975d6bSopenharmony_ci  * g_match_info_get_regex:
157b5975d6bSopenharmony_ci  * @match_info: a #GMatchInfo
158b5975d6bSopenharmony_ci@@ -956,13 +1014,28 @@ g_match_info_next (GMatchInfo  *match_info,
159b5975d6bSopenharmony_ci     }
160b5975d6bSopenharmony_ci 
161b5975d6bSopenharmony_ci   opts = map_to_pcre2_match_flags (match_info->regex->match_opts | match_info->match_opts);
162b5975d6bSopenharmony_ci-  match_info->matches = pcre2_match (match_info->regex->pcre_re,
163b5975d6bSopenharmony_ci-                                     (PCRE2_SPTR8) match_info->string,
164b5975d6bSopenharmony_ci-                                     match_info->string_len,
165b5975d6bSopenharmony_ci-                                     match_info->pos,
166b5975d6bSopenharmony_ci-                                     opts & ~G_REGEX_FLAGS_CONVERTED,
167b5975d6bSopenharmony_ci-                                     match_info->match_data,
168b5975d6bSopenharmony_ci-                                     match_info->match_context);
169b5975d6bSopenharmony_ci+
170b5975d6bSopenharmony_ci+  enable_jit_with_match_options (match_info->regex, opts);
171b5975d6bSopenharmony_ci+  if (match_info->regex->jit_status == JIT_STATUS_ENABLED)
172b5975d6bSopenharmony_ci+    {
173b5975d6bSopenharmony_ci+      match_info->matches = pcre2_jit_match (match_info->regex->pcre_re,
174b5975d6bSopenharmony_ci+                                             (PCRE2_SPTR8) match_info->string,
175b5975d6bSopenharmony_ci+                                             match_info->string_len,
176b5975d6bSopenharmony_ci+                                             match_info->pos,
177b5975d6bSopenharmony_ci+                                             opts & ~G_REGEX_FLAGS_CONVERTED,
178b5975d6bSopenharmony_ci+                                             match_info->match_data,
179b5975d6bSopenharmony_ci+                                             match_info->match_context);
180b5975d6bSopenharmony_ci+    }
181b5975d6bSopenharmony_ci+  else
182b5975d6bSopenharmony_ci+    {
183b5975d6bSopenharmony_ci+      match_info->matches = pcre2_match (match_info->regex->pcre_re,
184b5975d6bSopenharmony_ci+                                         (PCRE2_SPTR8) match_info->string,
185b5975d6bSopenharmony_ci+                                         match_info->string_len,
186b5975d6bSopenharmony_ci+                                         match_info->pos,
187b5975d6bSopenharmony_ci+                                         opts & ~G_REGEX_FLAGS_CONVERTED,
188b5975d6bSopenharmony_ci+                                         match_info->match_data,
189b5975d6bSopenharmony_ci+                                         match_info->match_context);
190b5975d6bSopenharmony_ci+    }
191b5975d6bSopenharmony_ci 
192b5975d6bSopenharmony_ci   if (IS_PCRE2_ERROR (match_info->matches))
193b5975d6bSopenharmony_ci     {
194b5975d6bSopenharmony_ci@@ -1582,6 +1655,7 @@ g_regex_new (const gchar         *pattern,
195b5975d6bSopenharmony_ci   regex->compile_opts = compile_options;
196b5975d6bSopenharmony_ci   regex->orig_compile_opts = orig_compile_opts;
197b5975d6bSopenharmony_ci   regex->match_opts = match_options;
198b5975d6bSopenharmony_ci+  enable_jit_with_match_options (regex, regex->match_opts);
199b5975d6bSopenharmony_ci 
200b5975d6bSopenharmony_ci   return regex;
201b5975d6bSopenharmony_ci }
202b5975d6bSopenharmony_ci@@ -1836,10 +1910,8 @@ g_regex_get_compile_flags (const GRegex *regex)
203b5975d6bSopenharmony_ci 
204b5975d6bSopenharmony_ci   g_return_val_if_fail (regex != NULL, 0);
205b5975d6bSopenharmony_ci 
206b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
207b5975d6bSopenharmony_ci   /* Preserve original G_REGEX_OPTIMIZE */
208b5975d6bSopenharmony_ci   extra_flags = (regex->orig_compile_opts & G_REGEX_OPTIMIZE);
209b5975d6bSopenharmony_ci-G_GNUC_END_IGNORE_DEPRECATIONS
210b5975d6bSopenharmony_ci 
211b5975d6bSopenharmony_ci   /* Also include the newline options */
212b5975d6bSopenharmony_ci   pcre2_pattern_info (regex->pcre_re, PCRE2_INFO_NEWLINE, &info_value);
213b5975d6bSopenharmony_cidiff --git a/glib/gregex.h b/glib/gregex.h
214b5975d6bSopenharmony_ciindex 7010d52ab8..30eb387073 100644
215b5975d6bSopenharmony_ci--- a/glib/gregex.h
216b5975d6bSopenharmony_ci+++ b/glib/gregex.h
217b5975d6bSopenharmony_ci@@ -262,11 +262,13 @@ GQuark g_regex_error_quark (void);
218b5975d6bSopenharmony_ci  *     followed by "?" behaves as if it were followed by "?:" but named
219b5975d6bSopenharmony_ci  *     parentheses can still be used for capturing (and they acquire numbers
220b5975d6bSopenharmony_ci  *     in the usual way).
221b5975d6bSopenharmony_ci- * @G_REGEX_OPTIMIZE: Optimize the regular expression. If the pattern will
222b5975d6bSopenharmony_ci- *     be used many times, then it may be worth the effort to optimize it
223b5975d6bSopenharmony_ci- *     to improve the speed of matches. Deprecated in GLib 2.74 which now uses
224b5975d6bSopenharmony_ci- *     libpcre2, which doesn’t require separate optimization of queries. This
225b5975d6bSopenharmony_ci- *     option is now a no-op. Deprecated: 2.74
226b5975d6bSopenharmony_ci+ * @G_REGEX_OPTIMIZE: Since 2.74 and the port to pcre2, requests JIT
227b5975d6bSopenharmony_ci+ *     compilation, which, if the just-in-time compiler is available, further
228b5975d6bSopenharmony_ci+ *     processes a compiled pattern into machine code that executes much
229b5975d6bSopenharmony_ci+ *     faster. However, it comes at the cost of extra processing before the
230b5975d6bSopenharmony_ci+ *     match is performed, so it is most beneficial to use this when the same
231b5975d6bSopenharmony_ci+ *     compiled pattern is used for matching many times. Before 2.74 this
232b5975d6bSopenharmony_ci+ *     option used the built-in non-JIT optimizations in pcre1.
233b5975d6bSopenharmony_ci  * @G_REGEX_FIRSTLINE: Limits an unanchored pattern to match before (or at) the
234b5975d6bSopenharmony_ci  *     first newline. Since: 2.34
235b5975d6bSopenharmony_ci  * @G_REGEX_DUPNAMES: Names used to identify capturing subpatterns need not
236b5975d6bSopenharmony_ci@@ -311,7 +313,7 @@ typedef enum
237b5975d6bSopenharmony_ci   G_REGEX_UNGREEDY          = 1 << 9,
238b5975d6bSopenharmony_ci   G_REGEX_RAW               = 1 << 11,
239b5975d6bSopenharmony_ci   G_REGEX_NO_AUTO_CAPTURE   = 1 << 12,
240b5975d6bSopenharmony_ci-  G_REGEX_OPTIMIZE GLIB_DEPRECATED_ENUMERATOR_IN_2_74 = 1 << 13,
241b5975d6bSopenharmony_ci+  G_REGEX_OPTIMIZE          = 1 << 13,
242b5975d6bSopenharmony_ci   G_REGEX_FIRSTLINE         = 1 << 18,
243b5975d6bSopenharmony_ci   G_REGEX_DUPNAMES          = 1 << 19,
244b5975d6bSopenharmony_ci   G_REGEX_NEWLINE_CR        = 1 << 20,
245b5975d6bSopenharmony_cidiff --git a/glib/tests/regex.c b/glib/tests/regex.c
246b5975d6bSopenharmony_ciindex 9a1977b248..bb1a5ff762 100644
247b5975d6bSopenharmony_ci--- a/glib/tests/regex.c
248b5975d6bSopenharmony_ci+++ b/glib/tests/regex.c
249b5975d6bSopenharmony_ci@@ -516,7 +516,7 @@ test_partial (gconstpointer d)
250b5975d6bSopenharmony_ci   GRegex *regex;
251b5975d6bSopenharmony_ci   GMatchInfo *match_info;
252b5975d6bSopenharmony_ci 
253b5975d6bSopenharmony_ci-  regex = g_regex_new (data->pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
254b5975d6bSopenharmony_ci+  regex = g_regex_new (data->pattern, data->compile_opts, G_REGEX_MATCH_DEFAULT, NULL);
255b5975d6bSopenharmony_ci 
256b5975d6bSopenharmony_ci   g_assert (regex != NULL);
257b5975d6bSopenharmony_ci 
258b5975d6bSopenharmony_ci@@ -534,12 +534,13 @@ test_partial (gconstpointer d)
259b5975d6bSopenharmony_ci   g_regex_unref (regex);
260b5975d6bSopenharmony_ci }
261b5975d6bSopenharmony_ci 
262b5975d6bSopenharmony_ci-#define TEST_PARTIAL_FULL(_pattern, _string, _match_opts, _expected) { \
263b5975d6bSopenharmony_ci+#define TEST_PARTIAL_FULL(_pattern, _string, _compile_opts, _match_opts, _expected) { \
264b5975d6bSopenharmony_ci   TestMatchData *data;                                          \
265b5975d6bSopenharmony_ci   gchar *path;                                                  \
266b5975d6bSopenharmony_ci   data = g_new0 (TestMatchData, 1);                             \
267b5975d6bSopenharmony_ci   data->pattern = _pattern;                                     \
268b5975d6bSopenharmony_ci   data->string = _string;                                       \
269b5975d6bSopenharmony_ci+  data->compile_opts = _compile_opts;                           \
270b5975d6bSopenharmony_ci   data->match_opts = _match_opts;                               \
271b5975d6bSopenharmony_ci   data->expected = _expected;                                   \
272b5975d6bSopenharmony_ci   path = g_strdup_printf ("/regex/match/partial/%d", ++total);  \
273b5975d6bSopenharmony_ci@@ -547,7 +548,7 @@ test_partial (gconstpointer d)
274b5975d6bSopenharmony_ci   g_free (path);                                                \
275b5975d6bSopenharmony_ci }
276b5975d6bSopenharmony_ci 
277b5975d6bSopenharmony_ci-#define TEST_PARTIAL(_pattern, _string, _expected) TEST_PARTIAL_FULL(_pattern, _string, G_REGEX_MATCH_PARTIAL, _expected)
278b5975d6bSopenharmony_ci+#define TEST_PARTIAL(_pattern, _string, _compile_opts, _expected) TEST_PARTIAL_FULL(_pattern, _string, _compile_opts, G_REGEX_MATCH_PARTIAL, _expected)
279b5975d6bSopenharmony_ci 
280b5975d6bSopenharmony_ci typedef struct {
281b5975d6bSopenharmony_ci   const gchar *pattern;
282b5975d6bSopenharmony_ci@@ -1504,7 +1505,7 @@ test_properties (void)
283b5975d6bSopenharmony_ci   gchar *str;
284b5975d6bSopenharmony_ci 
285b5975d6bSopenharmony_ci   error = NULL;
286b5975d6bSopenharmony_ci-  regex = g_regex_new ("\\p{L}\\p{Ll}\\p{Lu}\\p{L&}\\p{N}\\p{Nd}", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
287b5975d6bSopenharmony_ci+  regex = g_regex_new ("\\p{L}\\p{Ll}\\p{Lu}\\p{L&}\\p{N}\\p{Nd}", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
288b5975d6bSopenharmony_ci   res = g_regex_match (regex, "ppPP01", 0, &match);
289b5975d6bSopenharmony_ci   g_assert (res);
290b5975d6bSopenharmony_ci   str = g_match_info_fetch (match, 0);
291b5975d6bSopenharmony_ci@@ -1525,7 +1526,7 @@ test_class (void)
292b5975d6bSopenharmony_ci   gchar *str;
293b5975d6bSopenharmony_ci 
294b5975d6bSopenharmony_ci   error = NULL;
295b5975d6bSopenharmony_ci-  regex = g_regex_new ("[abc\\x{0B1E}\\p{Mn}\\x{0391}-\\x{03A9}]", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
296b5975d6bSopenharmony_ci+  regex = g_regex_new ("[abc\\x{0B1E}\\p{Mn}\\x{0391}-\\x{03A9}]", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
297b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a:b:\340\254\236:\333\253:\316\240", 0, &match);
298b5975d6bSopenharmony_ci   g_assert (res);
299b5975d6bSopenharmony_ci   str = g_match_info_fetch (match, 0);
300b5975d6bSopenharmony_ci@@ -1571,7 +1572,7 @@ test_lookahead (void)
301b5975d6bSopenharmony_ci   gint start, end;
302b5975d6bSopenharmony_ci 
303b5975d6bSopenharmony_ci   error = NULL;
304b5975d6bSopenharmony_ci-  regex = g_regex_new ("\\w+(?=;)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
305b5975d6bSopenharmony_ci+  regex = g_regex_new ("\\w+(?=;)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
306b5975d6bSopenharmony_ci   g_assert (regex);
307b5975d6bSopenharmony_ci   g_assert_no_error (error);
308b5975d6bSopenharmony_ci   res = g_regex_match (regex, "word1 word2: word3;", 0, &match);
309b5975d6bSopenharmony_ci@@ -1585,7 +1586,7 @@ test_lookahead (void)
310b5975d6bSopenharmony_ci   g_regex_unref (regex);
311b5975d6bSopenharmony_ci 
312b5975d6bSopenharmony_ci   error = NULL;
313b5975d6bSopenharmony_ci-  regex = g_regex_new ("foo(?!bar)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
314b5975d6bSopenharmony_ci+  regex = g_regex_new ("foo(?!bar)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
315b5975d6bSopenharmony_ci   g_assert (regex);
316b5975d6bSopenharmony_ci   g_assert_no_error (error);
317b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobar foobaz", 0, &match);
318b5975d6bSopenharmony_ci@@ -1600,7 +1601,7 @@ test_lookahead (void)
319b5975d6bSopenharmony_ci   g_regex_unref (regex);
320b5975d6bSopenharmony_ci 
321b5975d6bSopenharmony_ci   error = NULL;
322b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?!bar)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
323b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?!bar)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
324b5975d6bSopenharmony_ci   g_assert (regex);
325b5975d6bSopenharmony_ci   g_assert_no_error (error);
326b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobar foobaz", 0, &match);
327b5975d6bSopenharmony_ci@@ -1633,7 +1634,7 @@ test_lookbehind (void)
328b5975d6bSopenharmony_ci   gint start, end;
329b5975d6bSopenharmony_ci 
330b5975d6bSopenharmony_ci   error = NULL;
331b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<!foo)bar", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
332b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<!foo)bar", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
333b5975d6bSopenharmony_ci   g_assert (regex);
334b5975d6bSopenharmony_ci   g_assert_no_error (error);
335b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobar boobar", 0, &match);
336b5975d6bSopenharmony_ci@@ -1648,7 +1649,7 @@ test_lookbehind (void)
337b5975d6bSopenharmony_ci   g_regex_unref (regex);
338b5975d6bSopenharmony_ci 
339b5975d6bSopenharmony_ci   error = NULL;
340b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=bullock|donkey) poo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
341b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=bullock|donkey) poo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
342b5975d6bSopenharmony_ci   g_assert (regex);
343b5975d6bSopenharmony_ci   g_assert_no_error (error);
344b5975d6bSopenharmony_ci   res = g_regex_match (regex, "don poo, and bullock poo", 0, &match);
345b5975d6bSopenharmony_ci@@ -1661,17 +1662,17 @@ test_lookbehind (void)
346b5975d6bSopenharmony_ci   g_match_info_free (match);
347b5975d6bSopenharmony_ci   g_regex_unref (regex);
348b5975d6bSopenharmony_ci 
349b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<!dogs?|cats?) x", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
350b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<!dogs?|cats?) x", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
351b5975d6bSopenharmony_ci   g_assert (regex == NULL);
352b5975d6bSopenharmony_ci   g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND);
353b5975d6bSopenharmony_ci   g_clear_error (&error);
354b5975d6bSopenharmony_ci 
355b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=ab(c|de)) foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
356b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=ab(c|de)) foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
357b5975d6bSopenharmony_ci   g_assert (regex == NULL);
358b5975d6bSopenharmony_ci   g_assert_error (error, G_REGEX_ERROR, G_REGEX_ERROR_VARIABLE_LENGTH_LOOKBEHIND);
359b5975d6bSopenharmony_ci   g_clear_error (&error);
360b5975d6bSopenharmony_ci 
361b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=abc|abde)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
362b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=abc|abde)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
363b5975d6bSopenharmony_ci   g_assert (regex);
364b5975d6bSopenharmony_ci   g_assert_no_error (error);
365b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abfoo, abdfoo, abcfoo", 0, &match);
366b5975d6bSopenharmony_ci@@ -1683,7 +1684,7 @@ test_lookbehind (void)
367b5975d6bSopenharmony_ci   g_match_info_free (match);
368b5975d6bSopenharmony_ci   g_regex_unref (regex);
369b5975d6bSopenharmony_ci 
370b5975d6bSopenharmony_ci-  regex = g_regex_new ("^.*+(?<=abcd)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
371b5975d6bSopenharmony_ci+  regex = g_regex_new ("^.*+(?<=abcd)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
372b5975d6bSopenharmony_ci   g_assert (regex);
373b5975d6bSopenharmony_ci   g_assert_no_error (error);
374b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcabcabcabcabcabcabcabcabcd", 0, &match);
375b5975d6bSopenharmony_ci@@ -1692,7 +1693,7 @@ test_lookbehind (void)
376b5975d6bSopenharmony_ci   g_match_info_free (match);
377b5975d6bSopenharmony_ci   g_regex_unref (regex);
378b5975d6bSopenharmony_ci 
379b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=\\d{3})(?<!999)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
380b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=\\d{3})(?<!999)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
381b5975d6bSopenharmony_ci   g_assert (regex);
382b5975d6bSopenharmony_ci   g_assert_no_error (error);
383b5975d6bSopenharmony_ci   res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
384b5975d6bSopenharmony_ci@@ -1704,7 +1705,7 @@ test_lookbehind (void)
385b5975d6bSopenharmony_ci   g_match_info_free (match);
386b5975d6bSopenharmony_ci   g_regex_unref (regex);
387b5975d6bSopenharmony_ci 
388b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=\\d{3}...)(?<!999)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
389b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=\\d{3}...)(?<!999)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
390b5975d6bSopenharmony_ci   g_assert (regex);
391b5975d6bSopenharmony_ci   g_assert_no_error (error);
392b5975d6bSopenharmony_ci   res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
393b5975d6bSopenharmony_ci@@ -1716,7 +1717,7 @@ test_lookbehind (void)
394b5975d6bSopenharmony_ci   g_match_info_free (match);
395b5975d6bSopenharmony_ci   g_regex_unref (regex);
396b5975d6bSopenharmony_ci 
397b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=\\d{3}(?!999)...)foo", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
398b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=\\d{3}(?!999)...)foo", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
399b5975d6bSopenharmony_ci   g_assert (regex);
400b5975d6bSopenharmony_ci   g_assert_no_error (error);
401b5975d6bSopenharmony_ci   res = g_regex_match (regex, "999foo 123abcfoo 123foo", 0, &match);
402b5975d6bSopenharmony_ci@@ -1728,7 +1729,7 @@ test_lookbehind (void)
403b5975d6bSopenharmony_ci   g_match_info_free (match);
404b5975d6bSopenharmony_ci   g_regex_unref (regex);
405b5975d6bSopenharmony_ci 
406b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<=(?<!foo)bar)baz", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
407b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<=(?<!foo)bar)baz", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
408b5975d6bSopenharmony_ci   g_assert (regex);
409b5975d6bSopenharmony_ci   g_assert_no_error (error);
410b5975d6bSopenharmony_ci   res = g_regex_match (regex, "foobarbaz barfoobaz barbarbaz", 0, &match);
411b5975d6bSopenharmony_ci@@ -1753,7 +1754,7 @@ test_subpattern (void)
412b5975d6bSopenharmony_ci   gint start;
413b5975d6bSopenharmony_ci 
414b5975d6bSopenharmony_ci   error = NULL;
415b5975d6bSopenharmony_ci-  regex = g_regex_new ("cat(aract|erpillar|)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
416b5975d6bSopenharmony_ci+  regex = g_regex_new ("cat(aract|erpillar|)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
417b5975d6bSopenharmony_ci   g_assert (regex);
418b5975d6bSopenharmony_ci   g_assert_no_error (error);
419b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_capture_count (regex), ==, 1);
420b5975d6bSopenharmony_ci@@ -1771,7 +1772,7 @@ test_subpattern (void)
421b5975d6bSopenharmony_ci   g_match_info_free (match);
422b5975d6bSopenharmony_ci   g_regex_unref (regex);
423b5975d6bSopenharmony_ci 
424b5975d6bSopenharmony_ci-  regex = g_regex_new ("the ((red|white) (king|queen))", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
425b5975d6bSopenharmony_ci+  regex = g_regex_new ("the ((red|white) (king|queen))", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
426b5975d6bSopenharmony_ci   g_assert (regex);
427b5975d6bSopenharmony_ci   g_assert_no_error (error);
428b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_capture_count (regex), ==, 3);
429b5975d6bSopenharmony_ci@@ -1795,7 +1796,7 @@ test_subpattern (void)
430b5975d6bSopenharmony_ci   g_match_info_free (match);
431b5975d6bSopenharmony_ci   g_regex_unref (regex);
432b5975d6bSopenharmony_ci 
433b5975d6bSopenharmony_ci-  regex = g_regex_new ("the ((?:red|white) (king|queen))", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
434b5975d6bSopenharmony_ci+  regex = g_regex_new ("the ((?:red|white) (king|queen))", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
435b5975d6bSopenharmony_ci   g_assert (regex);
436b5975d6bSopenharmony_ci   g_assert_no_error (error);
437b5975d6bSopenharmony_ci   res = g_regex_match (regex, "the white queen", 0, &match);
438b5975d6bSopenharmony_ci@@ -1815,7 +1816,7 @@ test_subpattern (void)
439b5975d6bSopenharmony_ci   g_match_info_free (match);
440b5975d6bSopenharmony_ci   g_regex_unref (regex);
441b5975d6bSopenharmony_ci 
442b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?|(Sat)(ur)|(Sun))day (morning|afternoon)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
443b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?|(Sat)(ur)|(Sun))day (morning|afternoon)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
444b5975d6bSopenharmony_ci   g_assert (regex);
445b5975d6bSopenharmony_ci   g_assert_no_error (error);
446b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_capture_count (regex), ==, 3);
447b5975d6bSopenharmony_ci@@ -1835,7 +1836,7 @@ test_subpattern (void)
448b5975d6bSopenharmony_ci   g_match_info_free (match);
449b5975d6bSopenharmony_ci   g_regex_unref (regex);
450b5975d6bSopenharmony_ci 
451b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?|(abc)|(def))\\1", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
452b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?|(abc)|(def))\\1", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
453b5975d6bSopenharmony_ci   g_assert (regex);
454b5975d6bSopenharmony_ci   g_assert_no_error (error);
455b5975d6bSopenharmony_ci   g_assert_cmpint (g_regex_get_max_backref (regex), ==, 1);
456b5975d6bSopenharmony_ci@@ -1853,7 +1854,7 @@ test_subpattern (void)
457b5975d6bSopenharmony_ci   g_match_info_free (match);
458b5975d6bSopenharmony_ci   g_regex_unref (regex);
459b5975d6bSopenharmony_ci 
460b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?|(abc)|(def))(?1)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
461b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?|(abc)|(def))(?1)", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
462b5975d6bSopenharmony_ci   g_assert (regex);
463b5975d6bSopenharmony_ci   g_assert_no_error (error);
464b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcabc abcdef defabc defdef", 0, &match);
465b5975d6bSopenharmony_ci@@ -1870,7 +1871,7 @@ test_subpattern (void)
466b5975d6bSopenharmony_ci   g_match_info_free (match);
467b5975d6bSopenharmony_ci   g_regex_unref (regex);
468b5975d6bSopenharmony_ci 
469b5975d6bSopenharmony_ci-  regex = g_regex_new ("(?<DN>Mon|Fri|Sun)(?:day)?|(?<DN>Tue)(?:sday)?|(?<DN>Wed)(?:nesday)?|(?<DN>Thu)(?:rsday)?|(?<DN>Sat)(?:urday)?", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
470b5975d6bSopenharmony_ci+  regex = g_regex_new ("(?<DN>Mon|Fri|Sun)(?:day)?|(?<DN>Tue)(?:sday)?|(?<DN>Wed)(?:nesday)?|(?<DN>Thu)(?:rsday)?|(?<DN>Sat)(?:urday)?", G_REGEX_OPTIMIZE|G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
471b5975d6bSopenharmony_ci   g_assert (regex);
472b5975d6bSopenharmony_ci   g_assert_no_error (error);
473b5975d6bSopenharmony_ci   res = g_regex_match (regex, "Mon Tuesday Wed Saturday", 0, &match);
474b5975d6bSopenharmony_ci@@ -1897,7 +1898,7 @@ test_subpattern (void)
475b5975d6bSopenharmony_ci   g_match_info_free (match);
476b5975d6bSopenharmony_ci   g_regex_unref (regex);
477b5975d6bSopenharmony_ci 
478b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a|b\\1)+$", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
479b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a|b\\1)+$", G_REGEX_OPTIMIZE|G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT, &error);
480b5975d6bSopenharmony_ci   g_assert (regex);
481b5975d6bSopenharmony_ci   g_assert_no_error (error);
482b5975d6bSopenharmony_ci   res = g_regex_match (regex, "aaaaaaaaaaaaaaaa", 0, &match);
483b5975d6bSopenharmony_ci@@ -1921,7 +1922,7 @@ test_condition (void)
484b5975d6bSopenharmony_ci   gboolean res;
485b5975d6bSopenharmony_ci 
486b5975d6bSopenharmony_ci   error = NULL;
487b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a+)(\\()?[^()]+(?(-1)\\))(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
488b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a+)(\\()?[^()]+(?(-1)\\))(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
489b5975d6bSopenharmony_ci   g_assert (regex);
490b5975d6bSopenharmony_ci   g_assert_no_error (error);
491b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a(zzzzzz)b", 0, &match);
492b5975d6bSopenharmony_ci@@ -1935,7 +1936,7 @@ test_condition (void)
493b5975d6bSopenharmony_ci   g_regex_unref (regex);
494b5975d6bSopenharmony_ci 
495b5975d6bSopenharmony_ci   error = NULL;
496b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a+)(?<OPEN>\\()?[^()]+(?(<OPEN>)\\))(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
497b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a+)(?<OPEN>\\()?[^()]+(?(<OPEN>)\\))(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
498b5975d6bSopenharmony_ci   g_assert (regex);
499b5975d6bSopenharmony_ci   g_assert_no_error (error);
500b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a(zzzzzz)b", 0, &match);
501b5975d6bSopenharmony_ci@@ -1948,7 +1949,7 @@ test_condition (void)
502b5975d6bSopenharmony_ci   g_match_info_free (match);
503b5975d6bSopenharmony_ci   g_regex_unref (regex);
504b5975d6bSopenharmony_ci 
505b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(a+)(?(+1)\\[|\\<)?[^()]+(\\])?(b+)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
506b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(a+)(?(+1)\\[|\\<)?[^()]+(\\])?(b+)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
507b5975d6bSopenharmony_ci   g_assert (regex);
508b5975d6bSopenharmony_ci   g_assert_no_error (error);
509b5975d6bSopenharmony_ci   res = g_regex_match (regex, "a[zzzzzz]b", 0, &match);
510b5975d6bSopenharmony_ci@@ -1963,7 +1964,7 @@ test_condition (void)
511b5975d6bSopenharmony_ci 
512b5975d6bSopenharmony_ci   regex = g_regex_new ("(?(DEFINE) (?<byte> 2[0-4]\\d | 25[0-5] | 1\\d\\d | [1-9]?\\d) )"
513b5975d6bSopenharmony_ci                        "\\b (?&byte) (\\.(?&byte)){3} \\b",
514b5975d6bSopenharmony_ci-                       G_REGEX_EXTENDED, 0, &error);
515b5975d6bSopenharmony_ci+                       G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, 0, &error);
516b5975d6bSopenharmony_ci   g_assert (regex);
517b5975d6bSopenharmony_ci   g_assert_no_error (error);
518b5975d6bSopenharmony_ci   res = g_regex_match (regex, "128.0.0.1", 0, &match);
519b5975d6bSopenharmony_ci@@ -1982,7 +1983,7 @@ test_condition (void)
520b5975d6bSopenharmony_ci 
521b5975d6bSopenharmony_ci   regex = g_regex_new ("^(?(?=[^a-z]*[a-z])"
522b5975d6bSopenharmony_ci                        "\\d{2}-[a-z]{3}-\\d{2} | \\d{2}-\\d{2}-\\d{2} )$",
523b5975d6bSopenharmony_ci-                       G_REGEX_EXTENDED, 0, &error);
524b5975d6bSopenharmony_ci+                       G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, 0, &error);
525b5975d6bSopenharmony_ci   g_assert (regex);
526b5975d6bSopenharmony_ci   g_assert_no_error (error);
527b5975d6bSopenharmony_ci   res = g_regex_match (regex, "01-abc-24", 0, &match);
528b5975d6bSopenharmony_ci@@ -2015,7 +2016,7 @@ test_recursion (void)
529b5975d6bSopenharmony_ci   gint start;
530b5975d6bSopenharmony_ci 
531b5975d6bSopenharmony_ci   error = NULL;
532b5975d6bSopenharmony_ci-  regex = g_regex_new ("\\( ( [^()]++ | (?R) )* \\)", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
533b5975d6bSopenharmony_ci+  regex = g_regex_new ("\\( ( [^()]++ | (?R) )* \\)", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
534b5975d6bSopenharmony_ci   g_assert (regex);
535b5975d6bSopenharmony_ci   g_assert_no_error (error);
536b5975d6bSopenharmony_ci   res = g_regex_match (regex, "(middle)", 0, &match);
537b5975d6bSopenharmony_ci@@ -2032,7 +2033,7 @@ test_recursion (void)
538b5975d6bSopenharmony_ci   g_match_info_free (match);
539b5975d6bSopenharmony_ci   g_regex_unref (regex);
540b5975d6bSopenharmony_ci 
541b5975d6bSopenharmony_ci-  regex = g_regex_new ("^( \\( ( [^()]++ | (?1) )* \\) )$", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
542b5975d6bSopenharmony_ci+  regex = g_regex_new ("^( \\( ( [^()]++ | (?1) )* \\) )$", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
543b5975d6bSopenharmony_ci   g_assert (regex);
544b5975d6bSopenharmony_ci   g_assert_no_error (error);
545b5975d6bSopenharmony_ci   res = g_regex_match (regex, "((((((((((((((((middle))))))))))))))))", 0, &match);
546b5975d6bSopenharmony_ci@@ -2045,7 +2046,7 @@ test_recursion (void)
547b5975d6bSopenharmony_ci   g_match_info_free (match);
548b5975d6bSopenharmony_ci   g_regex_unref (regex);
549b5975d6bSopenharmony_ci 
550b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(?<pn> \\( ( [^()]++ | (?&pn) )* \\) )$", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
551b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(?<pn> \\( ( [^()]++ | (?&pn) )* \\) )$", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
552b5975d6bSopenharmony_ci   g_assert (regex);
553b5975d6bSopenharmony_ci   g_assert_no_error (error);
554b5975d6bSopenharmony_ci   g_regex_match (regex, "(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()", 0, &match);
555b5975d6bSopenharmony_ci@@ -2054,7 +2055,7 @@ test_recursion (void)
556b5975d6bSopenharmony_ci   g_match_info_free (match);
557b5975d6bSopenharmony_ci   g_regex_unref (regex);
558b5975d6bSopenharmony_ci 
559b5975d6bSopenharmony_ci-  regex = g_regex_new ("< (?: (?(R) \\d++ | [^<>]*+) | (?R)) * >", G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
560b5975d6bSopenharmony_ci+  regex = g_regex_new ("< (?: (?(R) \\d++ | [^<>]*+) | (?R)) * >", G_REGEX_OPTIMIZE|G_REGEX_EXTENDED, G_REGEX_MATCH_DEFAULT, &error);
561b5975d6bSopenharmony_ci   g_assert (regex);
562b5975d6bSopenharmony_ci   g_assert_no_error (error);
563b5975d6bSopenharmony_ci   res = g_regex_match (regex, "<ab<01<23<4>>>>", 0, &match);
564b5975d6bSopenharmony_ci@@ -2073,7 +2074,7 @@ test_recursion (void)
565b5975d6bSopenharmony_ci   g_match_info_free (match);
566b5975d6bSopenharmony_ci   g_regex_unref (regex);
567b5975d6bSopenharmony_ci 
568b5975d6bSopenharmony_ci-  regex = g_regex_new ("^((.)(?1)\\2|.)$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
569b5975d6bSopenharmony_ci+  regex = g_regex_new ("^((.)(?1)\\2|.)$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
570b5975d6bSopenharmony_ci   g_assert (regex);
571b5975d6bSopenharmony_ci   g_assert_no_error (error);
572b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcdcba", 0, &match);
573b5975d6bSopenharmony_ci@@ -2086,7 +2087,7 @@ test_recursion (void)
574b5975d6bSopenharmony_ci   g_match_info_free (match);
575b5975d6bSopenharmony_ci   g_regex_unref (regex);
576b5975d6bSopenharmony_ci 
577b5975d6bSopenharmony_ci-  regex = g_regex_new ("^(?:((.)(?1)\\2|)|((.)(?3)\\4|.))$", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, &error);
578b5975d6bSopenharmony_ci+  regex = g_regex_new ("^(?:((.)(?1)\\2|)|((.)(?3)\\4|.))$", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT, &error);
579b5975d6bSopenharmony_ci   g_assert (regex);
580b5975d6bSopenharmony_ci   g_assert_no_error (error);
581b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcdcba", 0, &match);
582b5975d6bSopenharmony_ci@@ -2099,7 +2100,7 @@ test_recursion (void)
583b5975d6bSopenharmony_ci   g_match_info_free (match);
584b5975d6bSopenharmony_ci   g_regex_unref (regex);
585b5975d6bSopenharmony_ci 
586b5975d6bSopenharmony_ci-  regex = g_regex_new ("^\\W*+(?:((.)\\W*+(?1)\\W*+\\2|)|((.)\\W*+(?3)\\W*+\\4|\\W*+.\\W*+))\\W*+$", G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT, &error);
587b5975d6bSopenharmony_ci+  regex = g_regex_new ("^\\W*+(?:((.)\\W*+(?1)\\W*+\\2|)|((.)\\W*+(?3)\\W*+\\4|\\W*+.\\W*+))\\W*+$", G_REGEX_OPTIMIZE|G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT, &error);
588b5975d6bSopenharmony_ci   g_assert (regex);
589b5975d6bSopenharmony_ci   g_assert_no_error (error);
590b5975d6bSopenharmony_ci   res = g_regex_match (regex, "abcdcba", 0, &match);
591b5975d6bSopenharmony_ci@@ -2219,26 +2220,18 @@ main (int argc, char *argv[])
592b5975d6bSopenharmony_ci   g_test_add_func ("/regex/compile-errors", test_compile_errors);
593b5975d6bSopenharmony_ci 
594b5975d6bSopenharmony_ci   /* TEST_NEW(pattern, compile_opts, match_opts) */
595b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
596b5975d6bSopenharmony_ci   TEST_NEW("[A-Z]+", G_REGEX_CASELESS | G_REGEX_EXTENDED | G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTBOL | G_REGEX_MATCH_PARTIAL);
597b5975d6bSopenharmony_ci-G_GNUC_END_IGNORE_DEPRECATIONS
598b5975d6bSopenharmony_ci   TEST_NEW("", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
599b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
600b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
601b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT);
602b5975d6bSopenharmony_ci-G_GNUC_END_IGNORE_DEPRECATIONS
603b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_MULTILINE, G_REGEX_MATCH_DEFAULT);
604b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_DOTALL, G_REGEX_MATCH_DEFAULT);
605b5975d6bSopenharmony_ci   TEST_NEW(".*", G_REGEX_DOTALL, G_REGEX_MATCH_NOTBOL);
606b5975d6bSopenharmony_ci   TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
607b5975d6bSopenharmony_ci   TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_CASELESS, G_REGEX_MATCH_DEFAULT);
608b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
609b5975d6bSopenharmony_ci   TEST_NEW("(123\\d*)[a-zA-Z]+(?P<hello>.*)", G_REGEX_CASELESS | G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT);
610b5975d6bSopenharmony_ci-G_GNUC_END_IGNORE_DEPRECATIONS
611b5975d6bSopenharmony_ci   TEST_NEW("(?P<A>x)|(?P<A>y)", G_REGEX_DUPNAMES, G_REGEX_MATCH_DEFAULT);
612b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
613b5975d6bSopenharmony_ci   TEST_NEW("(?P<A>x)|(?P<A>y)", G_REGEX_DUPNAMES | G_REGEX_OPTIMIZE, G_REGEX_MATCH_DEFAULT);
614b5975d6bSopenharmony_ci-G_GNUC_END_IGNORE_DEPRECATIONS
615b5975d6bSopenharmony_ci   /* This gives "internal error: code overflow" with pcre 6.0 */
616b5975d6bSopenharmony_ci   TEST_NEW("(?i)(?-i)", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
617b5975d6bSopenharmony_ci   TEST_NEW ("(?i)a", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
618b5975d6bSopenharmony_ci@@ -2249,9 +2242,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
619b5975d6bSopenharmony_ci   TEST_NEW ("(?U)[a-z]+", G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT);
620b5975d6bSopenharmony_ci 
621b5975d6bSopenharmony_ci   /* TEST_NEW_CHECK_FLAGS(pattern, compile_opts, match_ops, real_compile_opts, real_match_opts) */
622b5975d6bSopenharmony_ci-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
623b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("a", G_REGEX_OPTIMIZE, 0, G_REGEX_OPTIMIZE, 0);
624b5975d6bSopenharmony_ci-G_GNUC_END_IGNORE_DEPRECATIONS
625b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("a", G_REGEX_RAW, 0, G_REGEX_RAW, 0);
626b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("^.*", 0, 0, G_REGEX_ANCHORED, 0);
627b5975d6bSopenharmony_ci   TEST_NEW_CHECK_FLAGS ("(*UTF8)a", 0, 0, 0 /* this is the default in GRegex */, 0);
628b5975d6bSopenharmony_ci@@ -2540,18 +2531,35 @@ G_GNUC_END_IGNORE_DEPRECATIONS
629b5975d6bSopenharmony_ci   TEST_MATCH_COUNT("(a)?(b)", "b", 0, 0, 3);
630b5975d6bSopenharmony_ci   TEST_MATCH_COUNT("(a)?(b)", "ab", 0, 0, 3);
631b5975d6bSopenharmony_ci 
632b5975d6bSopenharmony_ci-  /* TEST_PARTIAL(pattern, string, expected) */
633b5975d6bSopenharmony_ci-  TEST_PARTIAL("^ab", "a", TRUE);
634b5975d6bSopenharmony_ci-  TEST_PARTIAL("^ab", "xa", FALSE);
635b5975d6bSopenharmony_ci-  TEST_PARTIAL("ab", "xa", TRUE);
636b5975d6bSopenharmony_ci-  TEST_PARTIAL("ab", "ab", FALSE); /* normal match. */
637b5975d6bSopenharmony_ci-  TEST_PARTIAL("a+b", "aa", TRUE);
638b5975d6bSopenharmony_ci-  TEST_PARTIAL("(a)+b", "aa", TRUE);
639b5975d6bSopenharmony_ci-  TEST_PARTIAL("a?b", "a", TRUE);
640b5975d6bSopenharmony_ci-
641b5975d6bSopenharmony_ci-  /* Test soft vs. hard partial matching */
642b5975d6bSopenharmony_ci-  TEST_PARTIAL_FULL("cat(fish)?", "cat", G_REGEX_MATCH_PARTIAL_SOFT, FALSE);
643b5975d6bSopenharmony_ci-  TEST_PARTIAL_FULL("cat(fish)?", "cat", G_REGEX_MATCH_PARTIAL_HARD, TRUE);
644b5975d6bSopenharmony_ci+  /* TEST_PARTIAL(pattern, string, expected), no JIT */
645b5975d6bSopenharmony_ci+  TEST_PARTIAL("^ab", "a", G_REGEX_DEFAULT, TRUE);
646b5975d6bSopenharmony_ci+  TEST_PARTIAL("^ab", "xa", G_REGEX_DEFAULT, FALSE);
647b5975d6bSopenharmony_ci+  TEST_PARTIAL("ab", "xa", G_REGEX_DEFAULT, TRUE);
648b5975d6bSopenharmony_ci+  TEST_PARTIAL("ab", "ab", G_REGEX_DEFAULT, FALSE); /* normal match. */
649b5975d6bSopenharmony_ci+  TEST_PARTIAL("a+b", "aa", G_REGEX_DEFAULT, TRUE);
650b5975d6bSopenharmony_ci+  TEST_PARTIAL("(a)+b", "aa", G_REGEX_DEFAULT, TRUE);
651b5975d6bSopenharmony_ci+  TEST_PARTIAL("a?b", "a", G_REGEX_DEFAULT, TRUE);
652b5975d6bSopenharmony_ci+
653b5975d6bSopenharmony_ci+  /* TEST_PARTIAL(pattern, string, expected) with JIT */
654b5975d6bSopenharmony_ci+  TEST_PARTIAL("^ab", "a", G_REGEX_OPTIMIZE, TRUE);
655b5975d6bSopenharmony_ci+  TEST_PARTIAL("^ab", "xa", G_REGEX_OPTIMIZE, FALSE);
656b5975d6bSopenharmony_ci+  TEST_PARTIAL("ab", "xa", G_REGEX_OPTIMIZE, TRUE);
657b5975d6bSopenharmony_ci+  TEST_PARTIAL("ab", "ab", G_REGEX_OPTIMIZE, FALSE); /* normal match. */
658b5975d6bSopenharmony_ci+  TEST_PARTIAL("a+b", "aa", G_REGEX_OPTIMIZE, TRUE);
659b5975d6bSopenharmony_ci+  TEST_PARTIAL("(a)+b", "aa", G_REGEX_OPTIMIZE, TRUE);
660b5975d6bSopenharmony_ci+  TEST_PARTIAL("a?b", "a", G_REGEX_OPTIMIZE, TRUE);
661b5975d6bSopenharmony_ci+
662b5975d6bSopenharmony_ci+  /* Test soft vs. hard partial matching, no JIT */
663b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("cat(fish)?", "cat", G_REGEX_DEFAULT, G_REGEX_MATCH_PARTIAL_SOFT, FALSE);
664b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("cat(fish)?", "cat", G_REGEX_DEFAULT, G_REGEX_MATCH_PARTIAL_HARD, TRUE);
665b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("ab+", "ab", G_REGEX_DEFAULT, G_REGEX_MATCH_PARTIAL_SOFT, FALSE);
666b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("ab+", "ab", G_REGEX_DEFAULT, G_REGEX_MATCH_PARTIAL_HARD, TRUE);
667b5975d6bSopenharmony_ci+
668b5975d6bSopenharmony_ci+  /* Test soft vs. hard partial matching with JIT */
669b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("cat(fish)?", "cat", G_REGEX_OPTIMIZE, G_REGEX_MATCH_PARTIAL_SOFT, FALSE);
670b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("cat(fish)?", "cat", G_REGEX_OPTIMIZE, G_REGEX_MATCH_PARTIAL_HARD, TRUE);
671b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("ab+", "ab", G_REGEX_OPTIMIZE, G_REGEX_MATCH_PARTIAL_SOFT, FALSE);
672b5975d6bSopenharmony_ci+  TEST_PARTIAL_FULL("ab+", "ab", G_REGEX_OPTIMIZE, G_REGEX_MATCH_PARTIAL_HARD, TRUE);
673b5975d6bSopenharmony_ci 
674b5975d6bSopenharmony_ci   /* TEST_SUB_PATTERN(pattern, string, start_position, sub_n, expected_sub,
675b5975d6bSopenharmony_ci    * 		      expected_start, expected_end) */
676b5975d6bSopenharmony_ci-- 
677b5975d6bSopenharmony_ciGitLab
678b5975d6bSopenharmony_ci
679