0

I'm using Google's C++ interface to PCRE to match a single regex multiple times (possibly thousands of times). From reading the PCRE manual, it seems like a good idea to let PCRE 'study' (spend time optimizing) the regex, however, I can't seem to find a way to do that with the C++ wrapper. The pcrecpp.h doesn't mention studying at all.

Is using pcre_study() worthwile, and if so, how can it be combined with pcrecpp and its RE class?

Wander Nauta
  • 18,832
  • 1
  • 45
  • 62

2 Answers2

2

From a quick scan of the PCRE++ source code, it appears that "studying" is impossible with this API because the compiled RE (pcre*) member of the RE wrapper object is private and there's no way to get it out or reset it.

If you want to know whether the studying optimization is worthwhile with your REs, the easiest option that I see is to copy pcrecpp.{cc,h} into your project and hack it in; the C++ API is just some thin wrapper code. You might even want to submit a patch upstream if, like me, you like to litter open source projects with your name and copyright ;)

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
0

For the benefit of people hitting on this question from a web search, I will point out that the ability to "study" an RE has been removed from PCRE2:

  1. Explicit "studying" of compiled patterns has been abolished - it now always happens automatically. JIT compiling is done by calling a new function, pcre2_jit_compile() after a successful return from pcre2_compile().

Reference: https://lists.exim.org/lurker/message/20150105.162835.0666407a.en.html

Michael Warner
  • 464
  • 1
  • 5
  • 13