Google's RE2 regular expression library
Posted Mar 13, 2010 19:24 UTC (Sat) by
tkil (subscriber, #1787)
In reply to:
Google's RE2 regular expression library by tzafrir
Parent article:
Google's RE2 regular expression library
Something like perl's qr// operator?
Not really; qr// simply lets the programmer control when the
double-quotish regex string is turned into a regex object. It's more like
generating an opcode tree for the regex, as opposed to compiling it down to
bytecode or machine instructions.
This is still a win, since the regex object creation step is often the most
expensive part of using a regex: it involves interpolation, compilation to
opcodes, and various optimizations. Doing that only once vs. every time
through a loop is a huge help.
Being able to compile down to machine instruction (with all the
optimizations along the way) is just going further along the scale of "more
effort up front" vs. "better speed on each match". When you're working
with long-lived C++ apps and the regexes are static, it makes perfect sense
to try to compile them down as far as possible; when working with short-
lived dynamic scripts, it isn't always a win.
(
Log in to post comments)