@@ -73,6 +73,11 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
73
73
PCRE2_SIZE erroroffset = 0 ;
74
74
m_pc = pcre2_compile (pcre2_pattern, PCRE2_ZERO_TERMINATED,
75
75
pcre2_options, &errornumber, &erroroffset, NULL );
76
+
77
+ m_pcje = pcre2_jit_compile (m_pc, PCRE2_JIT_COMPLETE);
78
+ m_pmc = pcre2_match_context_create (NULL );
79
+ m_pcjs = pcre2_jit_stack_create (32 *1024 , 512 *1024 , NULL );
80
+ pcre2_jit_stack_assign (m_pmc, NULL , m_pcjs);
76
81
#else
77
82
const char *errptr = NULL ;
78
83
int erroffset;
@@ -92,6 +97,8 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
92
97
Regex::~Regex () {
93
98
#if WITH_PCRE2
94
99
pcre2_code_free (m_pc);
100
+ pcre2_match_context_free (m_pmc);
101
+ pcre2_jit_stack_free (m_pcjs);
95
102
#else
96
103
if (m_pc != NULL ) {
97
104
pcre_free (m_pc);
@@ -118,8 +125,13 @@ std::list<SMatch> Regex::searchAll(const std::string& s) const {
118
125
119
126
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
120
127
do {
121
- rc = pcre2_match (m_pc, pcre2_s, s.length (),
122
- offset, 0 , match_data, NULL );
128
+ if (m_pcje == 0 ) {
129
+ rc = pcre2_jit_match (m_pc, pcre2_s, s.length (),
130
+ offset, 0 , match_data, m_pmc);
131
+ } else {
132
+ rc = pcre2_match (m_pc, pcre2_s, s.length (),
133
+ offset, 0 , match_data, m_pmc);
134
+ }
123
135
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
124
136
#else
125
137
const char *subject = s.c_str ();
@@ -159,7 +171,12 @@ bool Regex::searchOneMatch(const std::string& s, std::vector<SMatchCapture>& cap
159
171
#ifdef WITH_PCRE2
160
172
PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
161
173
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
162
- int rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, NULL );
174
+ int rc;
175
+ if (m_pcje == 0 ) {
176
+ rc = pcre2_jit_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, m_pmc);
177
+ } else {
178
+ rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, m_pmc);
179
+ }
163
180
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
164
181
#else
165
182
const char *subject = s.c_str ();
@@ -198,7 +215,7 @@ bool Regex::searchGlobal(const std::string& s, std::vector<SMatchCapture>& captu
198
215
pcre2_options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
199
216
}
200
217
int rc = pcre2_match (m_pc, pcre2_s, s.length (),
201
- startOffset, pcre2_options, match_data, NULL );
218
+ startOffset, pcre2_options, match_data, m_pmc );
202
219
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
203
220
204
221
#else
@@ -270,9 +287,14 @@ int Regex::search(const std::string& s, SMatch *match) const {
270
287
#ifdef WITH_PCRE2
271
288
PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
272
289
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
273
- int ret = pcre2_match (m_pc, pcre2_s, s.length (),
274
- 0 , 0 , match_data, NULL ) > 0 ;
275
-
290
+ int ret;
291
+ if (m_pcje == 0 ) {
292
+ ret = pcre2_match (m_pc, pcre2_s, s.length (),
293
+ 0 , 0 , match_data, m_pmc) > 0 ;
294
+ } else {
295
+ ret = pcre2_match (m_pc, pcre2_s, s.length (),
296
+ 0 , 0 , match_data, m_pmc) > 0 ;
297
+ }
276
298
if (ret > 0 ) { // match
277
299
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
278
300
#else
@@ -297,7 +319,12 @@ int Regex::search(const std::string& s) const {
297
319
#ifdef WITH_PCRE2
298
320
PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
299
321
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
300
- int rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, NULL );
322
+ int rc;
323
+ if (m_pcje == 0 ) {
324
+ rc = pcre2_jit_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, m_pmc);
325
+ } else {
326
+ rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, m_pmc);
327
+ }
301
328
pcre2_match_data_free (match_data);
302
329
if (rc > 0 ) {
303
330
return 1 ; // match
0 commit comments