[balsa/port-to-pcre2: 54/57] regex: Use PCRE2's JIT compiler




commit 538ead4242be899bd51083d7e829e84b18391a5d
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Tue Sep 8 10:27:11 2020 -0400

    regex: Use PCRE2's JIT compiler
    
    for faster matching.

 libbalsa/regex.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
diff --git a/libbalsa/regex.c b/libbalsa/regex.c
index 5b0f10363..8181b0149 100644
--- a/libbalsa/regex.c
+++ b/libbalsa/regex.c
@@ -73,6 +73,18 @@ libbalsa_regex_new(const gchar *pattern,
                     pattern, errorbuf);
     }
 
+    if (regex != NULL) {
+        errorcode = pcre2_jit_compile(regex, PCRE2_JIT_COMPLETE);
+        if (errorcode < 0) {
+            gchar errorbuf[120];
+
+            pcre2_get_error_message(errorcode, (PCRE2_UCHAR *) errorbuf, sizeof errorbuf);
+            g_set_error(error, LIBBALSA_REGEX_ERROR, LIBBALSA_REGEX_ERROR_JIT_COMPILE,
+                        "Error while JIT-compiling regular expression ā€œ%sā€: %s",
+                        pattern, errorbuf);
+        }
+    }
+
     return regex;
 }
 


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