@@ -73,6 +73,7 @@ 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
+ m_pcje = pcre2_jit_compile (m_pc, PCRE2_JIT_COMPLETE);
76
77
#else
77
78
const char *errptr = NULL ;
78
79
int erroffset;
@@ -118,8 +119,15 @@ std::list<SMatch> Regex::searchAll(const std::string& s) const {
118
119
119
120
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
120
121
do {
121
- rc = pcre2_match (m_pc, pcre2_s, s.length (),
122
- offset, 0 , match_data, NULL );
122
+ if (m_pcje == 0 ) {
123
+ rc = pcre2_jit_match (m_pc, pcre2_s, s.length (),
124
+ offset, 0 , match_data, NULL );
125
+ }
126
+
127
+ if (m_pcje != 0 || rc == PCRE2_ERROR_JIT_STACKLIMIT) {
128
+ rc = pcre2_match (m_pc, pcre2_s, s.length (),
129
+ offset, PCRE2_NO_JIT, match_data, NULL );
130
+ }
123
131
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
124
132
#else
125
133
const char *subject = s.c_str ();
@@ -159,7 +167,14 @@ bool Regex::searchOneMatch(const std::string& s, std::vector<SMatchCapture>& cap
159
167
#ifdef WITH_PCRE2
160
168
PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
161
169
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 );
170
+ int rc;
171
+ if (m_pcje == 0 ) {
172
+ rc = pcre2_jit_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, NULL );
173
+ }
174
+
175
+ if (m_pcje != 0 || rc == PCRE2_ERROR_JIT_STACKLIMIT) {
176
+ rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , PCRE2_NO_JIT, match_data, NULL );
177
+ }
163
178
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
164
179
#else
165
180
const char *subject = s.c_str ();
@@ -198,7 +213,7 @@ bool Regex::searchGlobal(const std::string& s, std::vector<SMatchCapture>& captu
198
213
pcre2_options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
199
214
}
200
215
int rc = pcre2_match (m_pc, pcre2_s, s.length (),
201
- startOffset, pcre2_options, match_data, NULL );
216
+ startOffset, pcre2_options, match_data, NULL );
202
217
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
203
218
204
219
#else
@@ -270,9 +285,16 @@ int Regex::search(const std::string& s, SMatch *match) const {
270
285
#ifdef WITH_PCRE2
271
286
PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
272
287
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
-
288
+ int ret;
289
+ if (m_pcje == 0 ) {
290
+ ret = pcre2_match (m_pc, pcre2_s, s.length (),
291
+ 0 , 0 , match_data, NULL ) > 0 ;
292
+ }
293
+
294
+ if (m_pcje != 0 || ret == PCRE2_ERROR_JIT_STACKLIMIT) {
295
+ ret = pcre2_match (m_pc, pcre2_s, s.length (),
296
+ 0 , PCRE2_NO_JIT, match_data, NULL ) > 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,14 @@ 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, NULL );
325
+ }
326
+
327
+ if (m_pcje != 0 || rc == PCRE2_ERROR_JIT_STACKLIMIT) {
328
+ rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , PCRE2_NO_JIT, match_data, NULL );
329
+ }
301
330
pcre2_match_data_free (match_data);
302
331
if (rc > 0 ) {
303
332
return 1 ; // match
0 commit comments