@@ -73,6 +73,7 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
7373 PCRE2_SIZE erroroffset = 0 ;
7474 m_pc = pcre2_compile (pcre2_pattern, PCRE2_ZERO_TERMINATED,
7575 pcre2_options, &errornumber, &erroroffset, NULL );
76+ m_pcje = pcre2_jit_compile (m_pc, PCRE2_JIT_COMPLETE);
7677#else
7778 const char *errptr = NULL ;
7879 int erroffset;
@@ -118,8 +119,15 @@ std::list<SMatch> Regex::searchAll(const std::string& s) const {
118119
119120 pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
120121 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+ }
123131 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
124132#else
125133 const char *subject = s.c_str ();
@@ -159,7 +167,14 @@ bool Regex::searchOneMatch(const std::string& s, std::vector<SMatchCapture>& cap
159167#ifdef WITH_PCRE2
160168 PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
161169 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+ }
163178 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
164179#else
165180 const char *subject = s.c_str ();
@@ -198,7 +213,7 @@ bool Regex::searchGlobal(const std::string& s, std::vector<SMatchCapture>& captu
198213 pcre2_options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
199214 }
200215 int rc = pcre2_match (m_pc, pcre2_s, s.length (),
201- startOffset, pcre2_options, match_data, NULL );
216+ startOffset, pcre2_options, match_data, NULL );
202217 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
203218
204219#else
@@ -270,9 +285,16 @@ int Regex::search(const std::string& s, SMatch *match) const {
270285#ifdef WITH_PCRE2
271286 PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
272287 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+ }
276298 if (ret > 0 ) { // match
277299 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
278300#else
@@ -297,7 +319,14 @@ int Regex::search(const std::string& s) const {
297319#ifdef WITH_PCRE2
298320 PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
299321 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+ }
301330 pcre2_match_data_free (match_data);
302331 if (rc > 0 ) {
303332 return 1 ; // match
0 commit comments