summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2013-06-18 14:44:12 +0100
committerDavid Mitchell <davem@iabyn.com>2013-07-28 10:33:35 +0100
commit7fadf4a7d2f1ec5af858f49a8493aacdee541a8b (patch)
tree371845744ff5c6ebfa93303c23054a69ed1adb91 /regexec.c
parent2c75e3628bc433543b3e475c87a64fb9e8d79871 (diff)
downloadperl-7fadf4a7d2f1ec5af858f49a8493aacdee541a8b.tar.gz
move intuit call from pp_match() into regexec()
Currently the main part of pp_match() looks like: if (can_use_intuit) { if (!intuit_start()) goto nope; if (can_match_based_only_on_intuit_result) { ... set up $&, $-[0] etc ... goto gotcha; } } if (!regexec(..., REXEC_CHECKED|r_flags)) goto nope; gotcha: ... This rather breaks the regex API encapulation. The caller of the regex engine shouldn't have to worry about whether to call intuit() or regexec(), and to know to set $& in the intuit-only case. So, move all the intuit-calling and $& setting into regexec itself. This is cleaner, and will also shortly allow us to enable intuit-only matches in pp_subst() too. After this change, the code above looks like (in its entirety): if (!regexec(..., r_flags)) goto nope; ... There, isn't that nicer?
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/regexec.c b/regexec.c
index dc4d288c2e..5a06f3b8b4 100644
--- a/regexec.c
+++ b/regexec.c
@@ -2234,6 +2234,36 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
"Matching");
);
+ if ((RX_EXTFLAGS(rx) & RXf_USE_INTUIT)
+ && !(flags & REXEC_CHECKED))
+ {
+ stringarg = re_intuit_start(rx, sv, strbeg, stringarg, strend,
+ flags, NULL);
+ if (!stringarg)
+ return 0;
+
+ if (RX_EXTFLAGS(rx) & RXf_CHECK_ALL) {
+ /* we can match based purely on the result of INTUIT.
+ * Set up captures etc just for $& and $-[0]
+ * (an intuit-only match wont have $1,$2,..) */
+ assert(!prog->nparens);
+ /* match via INTUIT shouldn't have any captures.
+ * Let @-, @+, $^N know */
+ prog->lastparen = prog->lastcloseparen = 0;
+ RX_MATCH_UTF8_set(rx, utf8_target);
+ if ( !(flags & REXEC_NOT_FIRST) )
+ Perl_reg_set_capture_string(aTHX_ rx,
+ strbeg, strend,
+ sv, flags, utf8_target);
+
+ prog->offs[0].start = stringarg - strbeg;
+ prog->offs[0].end = utf8_target
+ ? (char*)utf8_hop((U8*)stringarg, prog->minlenret) - strbeg
+ : stringarg - strbeg + prog->minlenret;
+ return 1;
+ }
+ }
+
/* at the end of this function, we'll do a LEAVE_SCOPE(oldsave),
* which will call destuctors to reset PL_regmatch_state, free higher