@@ -73,6 +73,11 @@ 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+
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);
7681#else
7782 const char *errptr = NULL ;
7883 int erroffset;
@@ -92,6 +97,8 @@ Regex::Regex(const std::string& pattern_, bool ignoreCase)
9297Regex::~Regex () {
9398#if WITH_PCRE2
9499 pcre2_code_free (m_pc);
100+ pcre2_match_context_free (m_pmc);
101+ pcre2_jit_stack_free (m_pcjs);
95102#else
96103 if (m_pc != NULL ) {
97104 pcre_free (m_pc);
@@ -118,8 +125,13 @@ std::list<SMatch> Regex::searchAll(const std::string& s) const {
118125
119126 pcre2_match_data *match_data = pcre2_match_data_create_from_pattern (m_pc, NULL );
120127 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+ }
123135 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
124136#else
125137 const char *subject = s.c_str ();
@@ -159,7 +171,12 @@ bool Regex::searchOneMatch(const std::string& s, std::vector<SMatchCapture>& cap
159171#ifdef WITH_PCRE2
160172 PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
161173 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+ }
163180 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
164181#else
165182 const char *subject = s.c_str ();
@@ -198,7 +215,7 @@ bool Regex::searchGlobal(const std::string& s, std::vector<SMatchCapture>& captu
198215 pcre2_options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
199216 }
200217 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 );
202219 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
203220
204221#else
@@ -270,9 +287,14 @@ int Regex::search(const std::string& s, SMatch *match) const {
270287#ifdef WITH_PCRE2
271288 PCRE2_SPTR pcre2_s = reinterpret_cast <PCRE2_SPTR>(s.c_str ());
272289 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+ }
276298 if (ret > 0 ) { // match
277299 PCRE2_SIZE *ovector = pcre2_get_ovector_pointer (match_data);
278300#else
@@ -297,7 +319,12 @@ 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, m_pmc);
325+ } else {
326+ rc = pcre2_match (m_pc, pcre2_s, s.length (), 0 , 0 , match_data, m_pmc);
327+ }
301328 pcre2_match_data_free (match_data);
302329 if (rc > 0 ) {
303330 return 1 ; // match
0 commit comments